Developer documentation | Axl-2.5.1

axlIntersection.cpp
Go to the documentation of this file.
1 /* axlIntersection.cpp ---
2  *
3  * Author: Anais Ducoffe
4  * Copyright (C) 2012, Anais Ducoffe, INRIA.
5  */
6 
7 /* Commentary:
8  */
9 
10 /* Change log:
11  *
12  */
13 #include "axlIntersection.h"
14 #include <axlCore/axlPoint.h>
15 #include <axlCore/axlLine.h>
17 
21 
22 class axlIntersectionPrivate{
23 
24 public :
25  //inputs
26  axlAbstractData * data1;
27  axlAbstractData * data2;
28  //output
29  axlPoint * output;
30 
31 };
32 
36 axlIntersection::axlIntersection(QObject *parent) : axlAbstractProcess(), d(new axlIntersectionPrivate){
37  d->data1 = NULL;
38  d->data2 = NULL;
39  d->output = NULL;
40 
41 }
42 
44  delete d;
45  d= NULL;
46 }
47 
48 
50  if(channel == 0)
51  return d->data1;
52  else
53  return d->data2;
54 }
55 
56 
57 
58 //dtkAbstractData *axlIntersection::output(int channel){
59 // if(channel < d->output.size()){
60 // return d->output.at(channel);
61 // }
62 //}
63 
64 dtkAbstractData *axlIntersection::output(void){
65  return d->output;
66 
67 }
68 
69 
70 void axlIntersection::setInput(dtkAbstractData *newData, int channel){
71  if(dynamic_cast<axlAbstractData *>(newData)){
72  axlAbstractData *axlData = dynamic_cast<axlAbstractData *>(newData);
73  if(channel == 0)
74  d->data1 = axlData;
75  else
76  d->data2 = axlData;
77  }
78 }
79 
81  // return d->output.size();
82  return 1;
83 }
84 
85 
87 
88  // if(!(d->output.empty())){
89  // d->output.clear();
90  // }
91 
92  if (dynamic_cast<axlLine *>(d->data1) && dynamic_cast<axlLine *>(d->data2)){
93 
94  axlLine *line2 = dynamic_cast<axlLine *>(d->data2);
95  axlLine *line1 = dynamic_cast<axlLine *>(d->data1);
96 
97  double a1 = line1->secondPoint()->x() - line1->firstPoint()->x();
98  double b1 = line1->secondPoint()->y() - line1->firstPoint()->y();
99  double c1 = line1->secondPoint()->z() - line1->firstPoint()->z();
100 
101  double a2 = line2->secondPoint()->x() - line2->firstPoint()->x();
102  double b2 = line2->secondPoint()->y() - line2->firstPoint()->y();
103  double c2 = line2->secondPoint()->z() - line2->firstPoint()->z();
104 
105 
106  double t1 = 0.0;
107  double t2 = 0.0;
108 
109  //compute solution
110  if(!(a2 == 0)){
111  double B = b1 - (b2/a2)*a1;
112  t1 = (1/B)* ((b2/a2)*(line1->firstPoint()->x() -line2->firstPoint()->x()) + (line2->firstPoint()->y() -line1->firstPoint()->y() ) );
113  t2 = (a1/a2)*t1 + ((line1->firstPoint()->x() -line2->firstPoint()->x())/a2) ;
114  }else if(!(a1 == 0)){
115  t1 = (line1->firstPoint()->x() -line2->firstPoint()->x())/a1;
116  t2 = (1/b2)*(b1*t1 + line1->firstPoint()->y() -line2->firstPoint()->y());
117  }
118 
119  // double xSol1 = a1*t1 + line1->firstPoint()->x();
120  // double ySol1 = b1*t1 + line1->firstPoint()->y();
121  double zSol1 = c1*t1 + line1->firstPoint()->z();
122 
123  double xSol2 = a2*t2 + line2->firstPoint()->x();
124  double ySol2 = b2*t2 + line2->firstPoint()->y();
125  double zSol2 = c2*t2 + line2->firstPoint()->z();
126 
127  if(std::abs(zSol1 -zSol2) < 0.01){
128  if(d->output == NULL){
129  d->output = new axlPoint(xSol2, ySol2, zSol2);
130  }else{
131  d->output->setCoordinates(xSol2, ySol2, zSol2);
132  }
133  //emit dataInserted(d->output);
134  return 1;
135  }
136  }
137  return 0;
138 }
139 
140 QString axlIntersection::description(void) const{
141  return "give the intersection point(s) between two axlData";
142 }
143 
144 
145 QString axlIntersection::identifier(void) const{
146  return "axlIntersection";
147 }
148 
149 dtkAbstractProcess *createaxlIntersectionProcess(void){
150  return new axlIntersection;
151 }
Class axlPoint defines 3D points.
Definition: axlPoint.h:34
axlAbstractData * getInput(int channel) const
Class axlLine defines 3D lines.
Definition: axlLine.h:35
axlPoint * secondPoint(void) const
Returns second point of the line.
Definition: axlLine.cpp:137
dtkAbstractProcess * createaxlIntersectionProcess(void)
virtual int update(void)
QString description(void) const
axlPoint * firstPoint(void) const
Returns first point of the line.
Definition: axlLine.cpp:128
axlIntersection(QObject *parent=0)
double y
Definition: axlPoint.h:37
double z
Definition: axlPoint.h:38
QString identifier(void) const
dtkAbstractData * output(void)
int channelCount(void)
double x
Definition: axlPoint.h:37
Class axlAbstractData defines an API for all type of axel data.
void setInput(dtkAbstractData *newData, int channel)