22 #include <dtkCoreSupport/dtkAbstractDataFactory.h>
28 class axlCircleArcConverterPrivate {
35 double angularResolution;
44 d->angularResolution = 0.02;
53 return "Converter from axlCircleArcConverter to axlMesh";
57 return "axlCircleArcConverter";
61 return QStringList() <<
"axlCircleArcConverter" <<
"axlCircleArc";
69 return dtkAbstractDataFactory::instance()->registerDataConverterType(
"axlCircleArcConverter", QStringList(),
"axlMesh",
createaxlCircleArcConverter);
102 int nbEdges = std::ceil(angle/d->angularResolution);
105 int arcIndex = d->output->push_back_new_edge();
108 if (d->startIndex == -1 && d->endIndex == -1) {
110 for (
int k = 0; k <= nbEdges; k++) {
112 double theta = k*angle / nbEdges;
114 axlPoint currPoint = c + cp1*std::cos(theta) + cpp2*std::sin(theta);
116 d->output->push_back_vertex(currPoint);
120 int nbPointsInMesh = d->output->vertex_count();
123 d->output->edgePushBack(arcIndex, nbPointsInMesh-nbEdges-1);
126 for (
int k = 0; k < nbPointsInMesh-1; k++) {
127 d->output->edgePushBack(arcIndex, k+1);
131 d->output->edgePushBack(arcIndex, nbPointsInMesh-2);
133 }
else if (d->startIndex != -1 && d->endIndex != -1) {
135 d->output->edgePushBack(arcIndex, d->startIndex);
138 for (
int k = 1; k <= nbEdges-1; k++) {
140 double theta = k*angle / nbEdges;
142 axlPoint currPoint = c + cp1*std::cos(theta) + cpp2*std::sin(theta);
144 d->output->edgePushBack(arcIndex, d->output->vertex_count());
146 d->output->push_back_vertex(currPoint);
150 d->output->edgePushBack(arcIndex, d->endIndex);
152 dtkError() <<
"Error within axlCircleArcConverter::toMesh: one point already exists and not the other one.";
156 d->output->vertex_show() =
false;
157 d->output->normal_used() =
false;
158 d->output->color_used() =
true;
159 d->output->edge_show() =
true;
160 d->output->face_show() =
false;
161 d->output->isPlanar() =
true;
163 d->output->setColor(d->data->color());
164 d->output->setOpacity(d->data->opacity());
165 d->output->setShader(d->data->shader());
171 if(
axlCircleArc* circleArc = dynamic_cast<axlCircleArc*>(data))
177 d->startIndex = index;
178 else if (channel == 1)
181 dtkWarn() <<
"axlCircleArcConverter::setParams usage: channel must be 0 or 1.";
185 d->output =
static_cast<axlMesh*
>(output);
Class axlPoint defines 3D points.
QString identifier(void) const
virtual void setPrecision(double eps)
virtual ~axlCircleArcConverter(void)
static bool registered(void)
axlCircleArcConverter(void)
dtkAbstractDataConverter * createaxlCircleArcConverter(void)
QString description(void) const
void setData(dtkAbstractData *data)
virtual void setOutput(axlAbstractData *output)
QStringList fromTypes(void) const
static double dotProduct(const axlPoint &lhs, const axlPoint &rhs)
static axlPoint crossProduct(const axlPoint &lhs, const axlPoint &rhs)
Returns the cross product between lhs (coords) and rhs (coords).
virtual void setParams(int channel, int index)
QString toType(void) const
Class axlAbstractData defines an API for all type of axel data.
Class axlMesh defines a piecewise-linear 3D object.
double angle(axlPoint vCompute, axlPoint vRef, axlPoint normal)