Medical Imaging Interaction Toolkit  2018.4.99-c4b6bb11
Medical Imaging Interaction Toolkit
mitkCone.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "mitkCone.h"
14 #include "mitkNumericTypes.h"
15 #include "vtkConeSource.h"
16 #include "vtkLinearTransform.h"
17 
19 {
20  // Set up Cone Surface. Radius 1.0, height 2.0, , centered around the origin
21  vtkConeSource *cone = vtkConeSource::New();
22  cone->SetRadius(1.0);
23  cone->SetHeight(2.0);
24  cone->SetDirection(0.0, -1.0, 0.0);
25  cone->SetCenter(0.0, 0.0, 0.0);
26  cone->SetResolution(20);
27  cone->CappingOn();
28  cone->Update();
29  SetVtkPolyData(cone->GetOutput());
30  cone->Delete();
31 }
32 
34 {
35 }
36 
37 bool mitk::Cone::IsInside(const Point3D &worldPoint) const
38 {
39  // transform point from world to object coordinates
40  ScalarType p[4];
41  p[0] = worldPoint[0];
42  p[1] = worldPoint[1];
43  p[2] = worldPoint[2];
44  p[3] = 1;
45 
46  GetGeometry()->GetVtkTransform()->GetInverse()->TransformPoint(p, p);
47 
48  p[1] += 1; // translate point, so that it fits to the formula below, which describes a cone that has its cone vertex
49  // at the origin
50  return (sqrt(p[0] * p[0] + p[2] * p[2]) <= p[1] * 0.5) && (p[1] <= 2); // formula to calculate if a given point is
51  // inside a cone that has its cone vertex at
52  // the origin, is aligned on the second axis,
53  // has a radius of one an a height of two
54 }
55 
57 {
58  TimeGeometry *geometry = GetTimeGeometry();
59  return geometry->GetExtentInWorld(0) * 0.5 * geometry->GetExtentInWorld(2) * 0.5 * vnl_math::pi / 3.0 *
60  geometry->GetExtentInWorld(1);
61 }
double ScalarType
vtkLinearTransform * GetVtkTransform() const
Get the m_IndexToWorldTransform as a vtkLinearTransform.
mitk::ScalarType GetVolume() override
Definition: mitkCone.cpp:56
superclass of all bounding objects (cylinder, cuboid,...)
const mitk::TimeGeometry * GetTimeGeometry() const
Return the TimeGeometry of the data as const pointer.
Definition: mitkBaseData.h:66
virtual void SetVtkPolyData(vtkPolyData *polydata, unsigned int t=0)
bool IsInside(const Point3D &p) const override
Definition: mitkCone.cpp:37
ScalarType GetExtentInWorld(unsigned int direction) const
Returns the Extend of the bounding in the given direction.
mitk::BaseGeometry * GetGeometry(int t=0) const
Return the geometry, which is a TimeGeometry, of the data as non-const pointer.
Definition: mitkBaseData.h:143
~Cone() override
Definition: mitkCone.cpp:33