ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkPhasedArray3DSpecialCoordinatesImage.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkPhasedArray3DSpecialCoordinatesImage_h
19 #define itkPhasedArray3DSpecialCoordinatesImage_h
20 
22 #include "itkPoint.h"
23 #include "itkMath.h"
26 
27 namespace itk
28 {
94 template< typename TPixel >
95 class ITK_TEMPLATE_EXPORT PhasedArray3DSpecialCoordinatesImage:
96  public SpecialCoordinatesImage< TPixel, 3 >
97 {
98 public:
105 
107  itkNewMacro(Self);
108 
111 
114  typedef TPixel PixelType;
115 
117  typedef TPixel ValueType;
118 
123  typedef TPixel InternalPixelType;
124 
125  typedef typename Superclass::IOPixelType IOPixelType;
126 
130 
135 
139 
144  itkStaticConstMacro(ImageDimension, unsigned int, 3);
145 
149 
151  typedef typename Superclass::OffsetType OffsetType;
152 
154  typedef typename Superclass::SizeType SizeType;
156 
159 
163  typedef typename Superclass::RegionType RegionType;
164 
171  typedef typename Superclass::SpacingType SpacingType;
172 
178 
182 
187  template< typename TCoordRep, typename TIndexRep >
189  const Point< TCoordRep, 3 > & point,
190  ContinuousIndex< TIndexRep, 3 > & index) const
191  {
192  const RegionType region = this->GetLargestPossibleRegion();
193  const double maxAzimuth = region.GetSize(0) - 1;
194  const double maxElevation = region.GetSize(1) - 1;
195 
196  // Convert Cartesian coordinates into angular coordinates
197  TCoordRep azimuth = Math::pi_over_2;
198  TCoordRep elevation = Math::pi_over_2;
199  if( point[2] != 0.0 )
200  {
201  azimuth = std::atan(point[0] / point[2]);
202  elevation = std::atan(point[1] / point[2]);
203  }
204  const TCoordRep radius = std::sqrt(point[0] * point[0]
205  + point[1] * point[1]
206  + point[2] * point[2]);
207 
208  // Convert the "proper" angular coordinates into index format
209  index[0] = static_cast< TCoordRep >( ( azimuth / m_AzimuthAngularSeparation )
210  + ( maxAzimuth / 2.0 ) );
211  index[1] = static_cast< TCoordRep >( ( elevation / m_ElevationAngularSeparation )
212  + ( maxElevation / 2.0 ) );
213  index[2] = static_cast< TCoordRep >( ( ( radius - m_FirstSampleDistance )
214  / m_RadiusSampleSize ) );
215 
216  // Now, check to see if the index is within allowed bounds
217  const bool isInside = region.IsInside(index);
218 
219  return isInside;
220  }
221 
226  template< typename TCoordRep >
228  const Point< TCoordRep, 3 > & point,
229  IndexType & index) const
230  {
231  const RegionType region = this->GetLargestPossibleRegion();
232  const double maxAzimuth = region.GetSize(0) - 1;
233  const double maxElevation = region.GetSize(1) - 1;
235 
236  // Convert Cartesian coordinates into angular coordinates
237  TCoordRep azimuth = Math::pi_over_2;
238  TCoordRep elevation = Math::pi_over_2;
239  if( point[2] != 0.0 )
240  {
241  azimuth = std::atan(point[0] / point[2]);
242  elevation = std::atan(point[1] / point[2]);
243  }
244  const TCoordRep radius = std::sqrt(point[0] * point[0]
245  + point[1] * point[1]
246  + point[2] * point[2]);
247 
248  // Convert the "proper" angular coordinates into index format
249  index[0] = static_cast< IndexValueType >(
250  ( azimuth / m_AzimuthAngularSeparation )
251  + ( maxAzimuth / 2.0 ) );
252  index[1] = static_cast< IndexValueType >(
253  ( elevation / m_ElevationAngularSeparation )
254  + ( maxElevation / 2.0 ) );
255  index[2] = static_cast< IndexValueType >(
256  ( ( radius - m_FirstSampleDistance )
257  / m_RadiusSampleSize ) );
258 
259  // Now, check to see if the index is within allowed bounds
260  const bool isInside = region.IsInside(index);
261 
262  return isInside;
263  }
264 
269  template< typename TCoordRep, typename TIndexRep >
271  const ContinuousIndex< TIndexRep, 3 > & index,
272  Point< TCoordRep, 3 > & point) const
273  {
274  const RegionType region = this->GetLargestPossibleRegion();
275  const double maxAzimuth = region.GetSize(0) - 1;
276  const double maxElevation = region.GetSize(1) - 1;
278 
279  // Convert the index into proper angular coordinates
280  const TCoordRep azimuth = ( index[0] - ( maxAzimuth / 2.0 ) )
281  * m_AzimuthAngularSeparation;
282  const TCoordRep elevation = ( index[1] - ( maxElevation / 2.0 ) )
283  * m_ElevationAngularSeparation;
284  const TCoordRep radius = ( index[2] * m_RadiusSampleSize ) + m_FirstSampleDistance;
285 
286  // Convert the angular coordinates into Cartesian coordinates
287  const TCoordRep tanOfAzimuth = std::tan(azimuth);
288  const TCoordRep tanOfElevation = std::tan(elevation);
289 
290  point[2] = static_cast< TCoordRep >( radius
291  / std::sqrt(1
292  + tanOfAzimuth * tanOfAzimuth
293  + tanOfElevation * tanOfElevation) );
294  point[1] = static_cast< TCoordRep >( point[2] * tanOfElevation );
295  point[0] = static_cast< TCoordRep >( point[2] * tanOfAzimuth );
296  }
297 
303  template< typename TCoordRep >
305  const IndexType & index,
306  Point< TCoordRep, 3 > & point) const
307  {
308  const RegionType region = this->GetLargestPossibleRegion();
309  const double maxAzimuth = region.GetSize(0) - 1;
310  const double maxElevation = region.GetSize(1) - 1;
312 
313  // Convert the index into proper angular coordinates
314  const TCoordRep azimuth =
315  ( static_cast< double >( index[0] ) - ( maxAzimuth / 2.0 ) )
316  * m_AzimuthAngularSeparation;
317  const TCoordRep elevation =
318  ( static_cast< double >( index[1] ) - ( maxElevation / 2.0 ) )
319  * m_ElevationAngularSeparation;
320  const TCoordRep radius =
321  ( static_cast< double >( index[2] ) * m_RadiusSampleSize )
322  + m_FirstSampleDistance;
323 
324  // Convert the angular coordinates into Cartesian coordinates
325  const TCoordRep tanOfAzimuth = std::tan(azimuth);
326  const TCoordRep tanOfElevation = std::tan(elevation);
327 
328  point[2] = static_cast< TCoordRep >(
329  radius / std::sqrt(
330  1.0 + tanOfAzimuth * tanOfAzimuth + tanOfElevation * tanOfElevation) );
331  point[1] = static_cast< TCoordRep >( point[2] * tanOfElevation );
332  point[0] = static_cast< TCoordRep >( point[2] * tanOfAzimuth );
333  }
334 
336  itkSetMacro(AzimuthAngularSeparation, double);
337 
339  itkSetMacro(ElevationAngularSeparation, double);
340 
342  itkSetMacro(RadiusSampleSize, double);
343 
345  itkSetMacro(FirstSampleDistance, double);
346 
347  template< typename TCoordRep >
350  {}
351 
352  template< typename TCoordRep >
356  {}
357 
360  { return AccessorType(); }
361 
363  const AccessorType GetPixelAccessor(void) const
364  { return AccessorType(); }
365 
368  { return NeighborhoodAccessorFunctorType(); }
369 
372  { return NeighborhoodAccessorFunctorType(); }
373 
374 protected:
376  {
377  m_RadiusSampleSize = 1;
378  m_AzimuthAngularSeparation = 1 * ( 2.0 * itk::Math::pi / 360.0 ); // 1
379  // degree
380  m_ElevationAngularSeparation = 1 * ( 2.0 * itk::Math::pi / 360.0 ); // 1
381  // degree
382  m_FirstSampleDistance = 0;
383  }
384 
385  virtual ~PhasedArray3DSpecialCoordinatesImage() ITK_OVERRIDE {}
386  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
387 
388 private:
389  ITK_DISALLOW_COPY_AND_ASSIGN(PhasedArray3DSpecialCoordinatesImage);
390 
391  double m_AzimuthAngularSeparation; // in radians
392  double m_ElevationAngularSeparation; // in radians
395 };
396 } // end namespace itk
397 
398 #ifndef ITK_MANUAL_INSTANTIATION
399 #include "itkPhasedArray3DSpecialCoordinatesImage.hxx"
400 #endif
401 
402 #endif
bool TransformPhysicalPointToIndex(const Point< TCoordRep, 3 > &point, IndexType &index) const
bool IsInside(const IndexType &index) const
signed long IndexValueType
Definition: itkIntTypes.h:150
An image region represents a structured region of data.
static ITK_CONSTEXPR_VAR double pi
Definition: itkMath.h:66
Templated n-dimensional nonrectilinear-coordinate image base class.
void TransformLocalVectorToPhysicalVector(FixedArray< TCoordRep, 3 > &) const
Implements a weak reference to an object.
unsigned long SizeValueType
Definition: itkIntTypes.h:143
Simulate a standard C array with copy semnatics.
Definition: itkFixedArray.h:50
Provides accessor interfaces to Get pixels and is meant to be used on pointers contained within Neigh...
void TransformContinuousIndexToPhysicalPoint(const ContinuousIndex< TIndexRep, 3 > &index, Point< TCoordRep, 3 > &point) const
const NeighborhoodAccessorFunctorType GetNeighborhoodAccessor() const
const SizeType & GetSize() const
Provides a common API for pixel accessors for Image and VectorImage.
void TransformIndexToPhysicalPoint(const IndexType &index, Point< TCoordRep, 3 > &point) const
A templated class holding a point in n-Dimensional image space.
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Templated 3D nonrectilinear-coordinate image class for phased-array &quot;range&quot; images.
bool TransformPhysicalPointToContinuousIndex(const Point< TCoordRep, 3 > &point, ContinuousIndex< TIndexRep, 3 > &index) const
Get the continuous index from a physical point.
ImportImageContainer< SizeValueType, PixelType > PixelContainer
Give access to partial aspects a type.
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:52
static ITK_CONSTEXPR_VAR double pi_over_2
Definition: itkMath.h:70
Base class for all data objects in ITK.
IndexType::IndexValueType IndexValueType
Definition: itkImageBase.h:140
Defines an itk::Image front-end to a standard C-array.
void TransformPhysicalVectorToLocalVector(const FixedArray< TCoordRep, 3 > &, FixedArray< TCoordRep, 3 > &) const