18 #include <dtkCoreSupport/dtkAbstractProcessFactory.h>
24 class axlProcessProjectionPrivate{
27 QPair <axlPoint *, axlLine *> inputs;
47 return d->inputs.first;
49 return d->inputs.second;
55 d->inputs.first =
dynamic_cast<axlPoint *
>(process->output());
66 if (d->inputs.first && d->inputs.second) {
67 double xa = d->inputs.second->firstPoint()->x();
68 double ya = d->inputs.second->firstPoint()->y();
69 double za = d->inputs.second->firstPoint()->z();
71 double a = d->inputs.second->secondPoint()->x() - xa;
72 double b = d->inputs.second->secondPoint()->y() - ya;
73 double c = d->inputs.second->secondPoint()->z() - za;
75 double x = d->inputs.first->x();
76 double y = d->inputs.first->y();
77 double z = d->inputs.first->z();
80 if ( d->inputs.first->isEqualTo(d->inputs.second->firstPoint()) ||
81 d->inputs.first->isEqualTo(d->inputs.second->secondPoint()) ) {
86 if (d->inputs.second->planeDirection() < 0) {
88 }
else if(d->inputs.second->planeDirection() > 0) {
92 if (a==0 && b ==0 && c ==0) {
93 return (x==xa && y ==ya && z==za);
99 QList<double> hasBeenComputed;
103 hasBeenComputed << ta;
107 hasBeenComputed << tb;
111 hasBeenComputed << tc;
113 if (hasBeenComputed.size() ==1) {
114 return (signe *hasBeenComputed.at(0)> 0 && signe*hasBeenComputed.at(0) < 1);
116 bool areEqual =
true;
117 for (
int i = 0; i < hasBeenComputed.size()-1; i++) {
118 if (!(hasBeenComputed.at(i)== hasBeenComputed.at(i+1))) {
126 dtkWarn() <<
"No inputs available";
134 return d->inputs.first;
140 if(dynamic_cast<axlPoint *>(newData)){
142 d->inputs.first = point;
144 qDebug() <<
"is not a point.";
146 }
else if(channel == 1){
147 if(dynamic_cast<axlLine *>(newData)){
149 d->inputs.second = line;
151 qDebug() <<
"is not a line.";
154 qDebug() <<
"channel has only two possible values : 0 and 1.";
167 double AB =
axlPoint::distance(d->inputs.second->secondPoint(), d->inputs.second->firstPoint());
168 double ABcarre = AB*AB;
172 d->inputs.first->setCoordinates(d->inputs.second->firstPoint()->x(),d->inputs.second->firstPoint()->y(),d->inputs.second->firstPoint()->z());
177 point1.
setCoordinates(d->inputs.second->firstPoint()->x()-d->inputs.first->x(),d->inputs.second->firstPoint()->y()-d->inputs.first->y() ,d->inputs.second->firstPoint()->z()-d->inputs.first->z() );
178 point2.
setCoordinates(d->inputs.second->secondPoint()->x()-d->inputs.second->firstPoint()->x(),d->inputs.second->secondPoint()->y()-d->inputs.second->firstPoint()->y() ,d->inputs.second->secondPoint()->z()-d->inputs.second->firstPoint()->z() );
180 scalarProduct = -1*scalarProduct;
182 double t = scalarProduct/ABcarre;
184 double x = d->inputs.second->firstPoint()->x() + t*(d->inputs.second->secondPoint()->x() - d->inputs.second->firstPoint()->x());
185 double y = d->inputs.second->firstPoint()->y() + t*(d->inputs.second->secondPoint()->y() - d->inputs.second->firstPoint()->y());
186 double z = d->inputs.second->firstPoint()->z() + t*(d->inputs.second->secondPoint()->z() - d->inputs.second->firstPoint()->z());
187 d->inputs.first->setCoordinates(x,y,z);
195 return "if the point is not on the line, axlProcessProjection projects it on the line";
200 return "axlProcessProjection";
205 return dtkAbstractProcessFactory::instance()->registerProcessType(
"axlProcessProjection",
createaxlProcessProjection,
"axlAbstractProcess");
Class axlPoint defines 3D points.
virtual axlAbstractData * getInput(int channel) const
virtual ~axlProcessProjection(void)
Class axlLine defines 3D lines.
virtual dtkAbstractData * output(void)
virtual QString identifier(void) const
void copyProcess(axlAbstractProcess *process)
static bool registered(void)
virtual void setInput(dtkAbstractData *newData, int channel)
static double dotProduct(const axlPoint &lhs, const axlPoint &rhs)
virtual QString description(void) const
axlProcessProjection(QObject *parent=0)
static double distance(const axlPoint &lhs, const axlPoint &rhs)
Returns the distance between lhs point and rhs point.
void setCoordinates(double x, double y, double z)
Change coordinates of this point.
dtkAbstractProcess * createaxlProcessProjection(void)
Class axlAbstractData defines an API for all type of axel data.