ITK  5.0.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:
99  ITK_DISALLOW_COPY_AND_ASSIGN(PhasedArray3DSpecialCoordinatesImage);
100 
107 
109  itkNewMacro(Self);
110 
113 
116  using PixelType = TPixel;
117 
119  using ValueType = TPixel;
120 
125  using InternalPixelType = TPixel;
126 
127  using IOPixelType = typename Superclass::IOPixelType;
128 
132 
137 
141 
146  static constexpr unsigned int ImageDimension = 3;
147 
151 
153  using OffsetType = typename Superclass::OffsetType;
154 
156  using SizeType = typename Superclass::SizeType;
158 
161 
166 
173  using SpacingType = typename Superclass::SpacingType;
174 
180 
184 
189  template< typename TCoordRep, typename TIndexRep >
191  const Point< TCoordRep, 3 > & point,
192  ContinuousIndex< TIndexRep, 3 > & index) const
193  {
194  const RegionType region = this->GetLargestPossibleRegion();
195  const double maxAzimuth = region.GetSize(0) - 1;
196  const double maxElevation = region.GetSize(1) - 1;
197 
198  // Convert Cartesian coordinates into angular coordinates
199  TCoordRep azimuth = Math::pi_over_2;
200  TCoordRep elevation = Math::pi_over_2;
201  if( point[2] != 0.0 )
202  {
203  azimuth = std::atan(point[0] / point[2]);
204  elevation = std::atan(point[1] / point[2]);
205  }
206  const TCoordRep radius = std::sqrt(point[0] * point[0]
207  + point[1] * point[1]
208  + point[2] * point[2]);
209 
210  // Convert the "proper" angular coordinates into index format
211  index[0] = static_cast< TCoordRep >( ( azimuth / m_AzimuthAngularSeparation )
212  + ( maxAzimuth / 2.0 ) );
213  index[1] = static_cast< TCoordRep >( ( elevation / m_ElevationAngularSeparation )
214  + ( maxElevation / 2.0 ) );
215  index[2] = static_cast< TCoordRep >( ( ( radius - m_FirstSampleDistance )
216  / m_RadiusSampleSize ) );
217 
218  // Now, check to see if the index is within allowed bounds
219  const bool isInside = region.IsInside(index);
220 
221  return isInside;
222  }
223 
228  template< typename TCoordRep >
230  const Point< TCoordRep, 3 > & point,
231  IndexType & index) const
232  {
233  const RegionType region = this->GetLargestPossibleRegion();
234  const double maxAzimuth = region.GetSize(0) - 1;
235  const double maxElevation = region.GetSize(1) - 1;
237 
238  // Convert Cartesian coordinates into angular coordinates
239  TCoordRep azimuth = Math::pi_over_2;
240  TCoordRep elevation = Math::pi_over_2;
241  if( point[2] != 0.0 )
242  {
243  azimuth = std::atan(point[0] / point[2]);
244  elevation = std::atan(point[1] / point[2]);
245  }
246  const TCoordRep radius = std::sqrt(point[0] * point[0]
247  + point[1] * point[1]
248  + point[2] * point[2]);
249 
250  // Convert the "proper" angular coordinates into index format
251  index[0] = static_cast< IndexValueType >(
252  ( azimuth / m_AzimuthAngularSeparation )
253  + ( maxAzimuth / 2.0 ) );
254  index[1] = static_cast< IndexValueType >(
255  ( elevation / m_ElevationAngularSeparation )
256  + ( maxElevation / 2.0 ) );
257  index[2] = static_cast< IndexValueType >(
258  ( ( radius - m_FirstSampleDistance )
259  / m_RadiusSampleSize ) );
260 
261  // Now, check to see if the index is within allowed bounds
262  const bool isInside = region.IsInside(index);
263 
264  return isInside;
265  }
266 
271  template< typename TCoordRep, typename TIndexRep >
273  const ContinuousIndex< TIndexRep, 3 > & index,
274  Point< TCoordRep, 3 > & point) const
275  {
276  const RegionType region = this->GetLargestPossibleRegion();
277  const double maxAzimuth = region.GetSize(0) - 1;
278  const double maxElevation = region.GetSize(1) - 1;
280 
281  // Convert the index into proper angular coordinates
282  const TCoordRep azimuth = ( index[0] - ( maxAzimuth / 2.0 ) )
283  * m_AzimuthAngularSeparation;
284  const TCoordRep elevation = ( index[1] - ( maxElevation / 2.0 ) )
285  * m_ElevationAngularSeparation;
286  const TCoordRep radius = ( index[2] * m_RadiusSampleSize ) + m_FirstSampleDistance;
287 
288  // Convert the angular coordinates into Cartesian coordinates
289  const TCoordRep tanOfAzimuth = std::tan(azimuth);
290  const TCoordRep tanOfElevation = std::tan(elevation);
291 
292  point[2] = static_cast< TCoordRep >( radius
293  / std::sqrt(1
294  + tanOfAzimuth * tanOfAzimuth
295  + tanOfElevation * tanOfElevation) );
296  point[1] = static_cast< TCoordRep >( point[2] * tanOfElevation );
297  point[0] = static_cast< TCoordRep >( point[2] * tanOfAzimuth );
298  }
299 
305  template< typename TCoordRep >
307  const IndexType & index,
308  Point< TCoordRep, 3 > & point) const
309  {
310  const RegionType region = this->GetLargestPossibleRegion();
311  const double maxAzimuth = region.GetSize(0) - 1;
312  const double maxElevation = region.GetSize(1) - 1;
314 
315  // Convert the index into proper angular coordinates
316  const TCoordRep azimuth =
317  ( static_cast< double >( index[0] ) - ( maxAzimuth / 2.0 ) )
318  * m_AzimuthAngularSeparation;
319  const TCoordRep elevation =
320  ( static_cast< double >( index[1] ) - ( maxElevation / 2.0 ) )
321  * m_ElevationAngularSeparation;
322  const TCoordRep radius =
323  ( static_cast< double >( index[2] ) * m_RadiusSampleSize )
324  + m_FirstSampleDistance;
325 
326  // Convert the angular coordinates into Cartesian coordinates
327  const TCoordRep tanOfAzimuth = std::tan(azimuth);
328  const TCoordRep tanOfElevation = std::tan(elevation);
329 
330  point[2] = static_cast< TCoordRep >(
331  radius / std::sqrt(
332  1.0 + tanOfAzimuth * tanOfAzimuth + tanOfElevation * tanOfElevation) );
333  point[1] = static_cast< TCoordRep >( point[2] * tanOfElevation );
334  point[0] = static_cast< TCoordRep >( point[2] * tanOfAzimuth );
335  }
336 
338  itkSetMacro(AzimuthAngularSeparation, double);
339 
341  itkSetMacro(ElevationAngularSeparation, double);
342 
344  itkSetMacro(RadiusSampleSize, double);
345 
347  itkSetMacro(FirstSampleDistance, double);
348 
349  template< typename TCoordRep >
352  {}
353 
354  template< typename TCoordRep >
358  {}
359 
362  { return AccessorType(); }
363 
366  { return AccessorType(); }
367 
370  { return NeighborhoodAccessorFunctorType(); }
371 
374  { return NeighborhoodAccessorFunctorType(); }
375 
376 protected:
378  {
379  m_RadiusSampleSize = 1;
380  m_AzimuthAngularSeparation = 1 * ( 2.0 * itk::Math::pi / 360.0 ); // 1
381  // degree
382  m_ElevationAngularSeparation = 1 * ( 2.0 * itk::Math::pi / 360.0 ); // 1
383  // degree
384  m_FirstSampleDistance = 0;
385  }
386 
387  ~PhasedArray3DSpecialCoordinatesImage() override = default;
388  void PrintSelf(std::ostream & os, Indent indent) const override;
389 
390 private:
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
static constexpr double pi_over_2
Definition: itkMath.h:67
bool TransformPhysicalPointToIndex(const Point< TCoordRep, 3 > &point, IndexType &index) const
unsigned long SizeValueType
Definition: itkIntTypes.h:83
bool IsInside(const IndexType &index) const
static constexpr double pi
Definition: itkMath.h:63
An image region represents a structured region of data.
Templated n-dimensional nonrectilinear-coordinate image base class.
void TransformLocalVectorToPhysicalVector(FixedArray< TCoordRep, 3 > &) const
Implements a weak reference to an object.
typename PixelContainer::ConstPointer PixelContainerConstPointer
Simulate a standard C array with copy semnatics.
Definition: itkFixedArray.h:51
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
signed long IndexValueType
Definition: itkIntTypes.h:90
const NeighborhoodAccessorFunctorType GetNeighborhoodAccessor() const
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:68
Represent a n-dimensional offset between two n-dimensional indexes of n-dimensional image...
Definition: itkOffset.h:67
const SizeType & GetSize() const
typename SizeType::SizeValueType SizeValueType
Definition: itkImageBase.h:142
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.
Give access to partial aspects a type.
Base class for most ITK classes.
Definition: itkObject.h:60
typename IndexType::IndexValueType IndexValueType
Definition: itkImageBase.h:133
Base class for all data objects in ITK.
Defines an itk::Image front-end to a standard C-array.
void TransformPhysicalVectorToLocalVector(const FixedArray< TCoordRep, 3 > &, FixedArray< TCoordRep, 3 > &) const