Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
DistanceMeasureControl.cpp
1 #include "DistanceMeasureControl.hh"
2 
3 #include <Base/Math/Vector3.hh>
4 #include <Gui/biasgl.h>
5 
6 using namespace BIAS;
7 using namespace BIAS;
8 using namespace std;
9 
10 
13 {
14  bDistMeasureActivated_ = false;
15  dNumClick_ =0;
16  bIsInitialized_ = false;
17  firstHomgPoint_.Set(0.0,0.0,0.0,1.0);
18  secondHomgPoint_.Set(0.0,0.0,0.0,1.0);
19 }
20 
21 
24  bDistMeasureActivated_=on;
25 }
26 
29  return bDistMeasureActivated_;
30 }
31 
33 LeftMouseDoubleClicked(int x, int y, int m)
34 {
35  if (! UseLeftDouble_) {
36  return false;
37  }
38  if(bDistMeasureActivated_){
39  // Get from 2D mouse position 3D point in scene.
40  if(!controlledObject_->GetViewportCoordinates(x, y)) {
41  BIASERR("outside used viewport!");
42  return false;
43  }
44 
45  BIAS::HomgPoint3D homgPoint=controlledObject_->UnProject(x, y);
46 
47  if (!(homgPoint[3] == 0.0)) {
48  //cout << "DistanceMeasureControl::LeftMouseDoubleClicked("<<x<<","<<y<<") : "
49  //<< "Setting point at("<< homgPoint[0] << ", "<< homgPoint[1] << ", "
50  //<< homgPoint[2] << "). "<< endl;
51 
52  if(dNumClick_==0 || dNumClick_ ==2){
53  dNumClick_ = 1;
54  firstHomgPoint_ = homgPoint;
55  secondHomgPoint_.Set(0.0,0.0,0.0,1.0);
56  }
57  else if(dNumClick_==1){
58  dNumClick_ = 2;
59  secondHomgPoint_ = homgPoint;
60  double dist = secondHomgPoint_.Distance(firstHomgPoint_);
61  cout<<"Final Distance: "<<dist<<endl;
62  }
63  return true;
64  }
65  else return false;
66  }
67  else{
69  }
70  return false;
71 }
72 
74 MouseMoved(int x, int y){
75  x_ = x;
76  y_ = y;
77  //cout<<"MOVE:"<<x<<","<<y<<endl;
78  return true;
79 }
80 
82 Draw(){
83 
84  if (!bIsInitialized_) {
85 #ifdef BIAS_HAVE_FONTGL
86  if (drawer_.InitFont(NULL) != 0){
87  cerr<<"init of font failed ..."<<endl;
88  return;
89  }
90 #else
91  BIASWARNONCE("FontGL is disabled in BIAS.");
92  return;
93 #endif
94  bIsInitialized_ = true;
95  }
96 
97  if(bDistMeasureActivated_ && dNumClick_==1){
98  BIAS::HomgPoint3D homgPoint = controlledObject_->UnProject(x_, y_);
99  if (!(homgPoint[3] == 0.0)) {
100  double dist = homgPoint.Distance(firstHomgPoint_);
101 
102  float red[4] = {1.0, 0.0, 0.0, 1.0};
103  float white[4] = {1.0, 1.0, 1.0, 1.0};
104  float black[4] = {0.0, 0.0, 0.0, 1.0};
105  glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, black);
106  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, red);
107  glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white);
108 
109  glColor3f(1.0, 0.0, 0.0);
110  glBegin(GL_LINES);
111  glVertex3d(firstHomgPoint_[0],firstHomgPoint_[1], firstHomgPoint_[2]);
112  glVertex3d(homgPoint[0],homgPoint[1], homgPoint[2]);
113  glEnd();
114  //cout<<"Distance: "<<dist<<endl;
115  stringstream text; text<<dist<<endl;
116 
117 #ifdef BIAS_HAVE_FONTGL
118  glDisable(GL_DEPTH_TEST);
119  drawer_.Print3D(text.str(),homgPoint[0],homgPoint[1],homgPoint[2]);
120  glEnable(GL_DEPTH_TEST);
121 #endif
122 
123 
124  }
125  }
126 }
127 
bool GetDistanceMeasure()
Return if the measurement mode is activated.
bool LeftMouseDoubleClicked(int x, int y, int m)
Sets first or second click measurement positions.
virtual bool LeftMouseDoubleClicked(int x, int y, int m)
Computes from the coordinates x,y a 3D point in the scene and tries to set it to the point of interes...
void Set(const HOMGPOINT3D_TYPE &x, const HOMGPOINT3D_TYPE &y, const HOMGPOINT3D_TYPE &z)
set elementwise with given 3 euclidean scalar values.
Definition: HomgPoint3D.hh:321
bool MouseMoved(int x, int y)
Sets intermediate coords.
virtual void Draw()
overloaded method from SceneBase.
HOMGPOINT3D_TYPE Distance(const HomgPoint3D &point) const
Definition: HomgPoint3D.hh:404
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
Definition: HomgPoint3D.hh:61
void SetDistanceMeasure(bool on)
Activate or deactivate distance measurement.