Orfeo Toolbox  3.16
itkArrowSpatialObject.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkArrowSpatialObject.txx,v $
5  Language: C++
6  Date: $Date: 2008-06-29 01:56:09 $
7  Version: $Revision: 1.11 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkArrowSpatialObject_txx
18 #define __itkArrowSpatialObject_txx
19 
20 #include "itkArrowSpatialObject.h"
21 #include "itkEuler3DTransform.h"
22 
23 namespace itk
24 {
25 
27 template< unsigned int TDimension >
30 {
31  this->SetDimension(TDimension);
32  this->SetTypeName ("ArrowSpatialObject");
33  this->GetProperty()->SetRed(1);
34  this->GetProperty()->SetGreen(0);
35  this->GetProperty()->SetBlue(0);
36  this->GetProperty()->SetAlpha(1);
37 
38  m_Direction.Fill(0);
39  m_Direction[0] = 1; // along the x direction by default
40  m_Position.Fill(0);
41  m_Length = 1;
42 
43  this->ComputeBoundingBox();
44 }
45 
47 template< unsigned int TDimension >
50 {
51 }
52 
53 
55 template< unsigned int TDimension >
56 void
58 ::SetLength(double length)
59 {
60  m_Length = length;
61  double spacing[TDimension];
62  spacing[0] = m_Length;
63 
64  for(unsigned int i=1;i<TDimension;i++)
65  {
66  spacing[i] = 1;
67  }
68  this->SetSpacing(spacing);
69  this->Modified();
70 }
71 
72 
74 template< unsigned int TDimension >
75 bool
78 {
79  itkDebugMacro( "Computing Rectangle bounding box" );
80 
81  if( this->GetBoundingBoxChildrenName().empty()
82  || strstr(typeid(Self).name(), this->GetBoundingBoxChildrenName().c_str()) )
83  {
84  PointType pnt = this->GetPosition();
85  PointType pnt2;
86  for(unsigned int i=0; i<TDimension;i++)
87  {
88  pnt2[i]=pnt[i]+m_Length*m_Direction[i];
89  }
90 
91  pnt = this->GetIndexToWorldTransform()->TransformPoint(pnt);
92  pnt2 = this->GetIndexToWorldTransform()->TransformPoint(pnt2);
93 
94  const_cast<typename Superclass::BoundingBoxType*>(
95  this->GetBounds())->SetMinimum(pnt);
96  const_cast<typename Superclass::BoundingBoxType*>(
97  this->GetBounds())->SetMaximum(pnt2);
98  }
99  return true;
100 }
101 
103 template< unsigned int TDimension >
104 bool
106 ::IsInside( const PointType & point, unsigned int depth, char * name ) const
107 {
108  itkDebugMacro( "Checking the point [" << point << "] is on the Line" );
109 
110  if(name == NULL)
111  {
112  if(IsInside(point))
113  {
114  return true;
115  }
116  }
117  else if(strstr(typeid(Self).name(), name))
118  {
119  if(IsInside(point))
120  {
121  return true;
122  }
123  }
124 
125  return Superclass::IsInside(point, depth, name);
126 }
127 
128 
132 template< unsigned int TDimension >
133 bool
135 ::IsInside( const PointType & point) const
136 {
137  if( !this->SetInternalInverseTransformToWorldToIndexTransform() )
138  {
139  return false;
140  }
141 
142  PointType transformedPoint =
143  this->GetInternalInverseTransform()->TransformPoint(point);
144 
145  this->ComputeLocalBoundingBox();
146 
147  if( this->GetBounds()->IsInside(transformedPoint) )
148  {
149  // If the transformedPoint lies on the line between the two points
150  PointType pnt = this->GetPosition();
151  PointType pnt2;
152  for(unsigned int i=0; i<TDimension;i++)
153  {
154  pnt2[i]=pnt[i]+m_Length*m_Direction[i];
155  }
156 
157  VectorType v = pnt2-pnt;
158  VectorType v2 = transformedPoint-pnt;
159 
160  v.Normalize();
161  v2.Normalize();
162 
163  if(dot_product(v.GetVnlVector(),v2.GetVnlVector()) == 1)
164  {
165  return true;
166  }
167  }
168 
169  return false;
170 }
171 
172 
174 template< unsigned int TDimension >
175 void
178 {
179  VectorType offset;
180  for(unsigned int i=0;i<TDimension;i++)
181  {
182  offset[i] = m_Position[i];
183  }
184  this->GetObjectToParentTransform()->SetOffset(offset);
185 
186  // If the given direction is not normalized we set the length of the vector
187  // as the length of the arrow
188  m_Length = m_Direction.GetSquaredNorm();
189 
190  if(m_Length != 0.0)
191  {
192  m_Length = vcl_sqrt(m_Length);
193  }
194  else
195  {
196  this->Modified();
197  return;
198  }
199 
200  m_Direction.Normalize();
201 
202 #ifndef __BORLANDC__
203 #if(TDimension == 3)
204 
205  typedef itk::Euler3DTransform<double> EulerTransformType;
206  EulerTransformType::Pointer euler = EulerTransformType::New();
207 
208  double angley;
209  double anglez = 0;
210 
211  #ifndef PI
212  const double PI = 4.0 * vcl_atan(1.0 );
213  #endif
214 
215  if(m_Direction[0] == 0.0)
216  {
217  if(m_Direction[1]>0.0)
218  {
219  anglez=PI/2;
220  }
221  else if(m_Direction[1]<0.0)
222  {
223  anglez=-PI/2;
224  }
225  }
226  else
227  {
228  if(m_Direction[0]<0.0)
229  {
230  anglez = PI+vcl_atan(m_Direction[1]/m_Direction[0]);
231  }
232  else
233  {
234  anglez = vcl_atan(m_Direction[1]/m_Direction[0]);
235  }
236  }
237  angley = -asin(m_Direction[2]);
238  euler->SetRotation(0,angley,anglez);
239  this->GetObjectToParentTransform()->SetMatrix(euler->GetRotationMatrix());
240 #endif
241 #endif
242 
243  this->Modified();
244 }
245 
247 template< unsigned int TDimension >
248 void
250 ::PrintSelf( std::ostream& os, Indent indent ) const
251 {
252  os << indent << "ArrowSpatialObject(" << this << ")" << std::endl;
253  Superclass::PrintSelf( os, indent );
254  os << indent << "Position = " << m_Position << std::endl;
255  os << indent << "Direction = " << m_Direction << std::endl;
256  os << indent << "Length = " << m_Length << std::endl;
257 }
258 
259 } // end namespace itk
260 
261 #endif // end __itkArrowSpatialObject_txx

Generated at Sat Feb 2 2013 23:24:10 for Orfeo Toolbox with doxygen 1.8.1.1