NorMIT-nav  16.5
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxSimpleSyntheticVolume.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
34 
35 #include "cxTypeConversions.h"
36 
37 namespace cx {
38 
40  : cxSyntheticVolume(bounds)
41 {
42 }
43 
45 {
46  std::cout << QString("Volume: Simple, bounds=[%1]")
47  .arg(qstring_cast(mBounds))
48  << std::endl;
49 }
50 
52  float y,
53  float thickness,
54  int n_lines,
55  int axis) const
56 {
57  float linespacing = mBounds(axis)/n_lines;
58 
59  for(int i = 0; i < n_lines; i++)
60  {
61  if(x > i*linespacing + linespacing/2 && x < i*linespacing + thickness + linespacing/2)
62  {
63  if(y > 0.0f && y < thickness)
64  {
65  return true;
66  }
67  }
68  }
69  return false;
70 }
71 
72 unsigned char cxSimpleSyntheticVolume::evaluate(const cx::Vector3D &p) const
73 {
74  float x = p[0];
75  float y = p[1];
76  float z = p[2];
77 
78  // Let's make a block in the middle of the volume
79  if(x > mBounds(0)/3 && x < 2*mBounds(0)/3
80  && y > mBounds(1)/3 && y < 2*mBounds(1)/3
81  && z > mBounds(2)/3 && z < 2*mBounds(2)/3)
82  {
83  return 255;
84  }
85 
86  // A set of thin lines with traversing in each of the directions
87 
88  // Z direction
89  if(isOnLine(x, y-2.0f, 0.5f, 5, 2))
90  {
91  return 255;
92  }
93 
94  if(isOnLine(x, y-3.0f, 0.25f, 5, 2))
95  {
96  return 255;
97  }
98 
99  if(isOnLine(x, y-4.0f, 0.125f, 5, 2))
100  {
101  return 255;
102  }
103  if(isOnLine(x, y-5.0f, 0.0625f, 5, 2))
104  {
105  return 255;
106  }
107 
108  // Y direction
109  if(isOnLine(x, z-2.0f, 0.5f, 5, 1))
110  {
111  return 255;
112  }
113 
114  if(isOnLine(x, z-3.0f, 0.25f, 5, 1))
115  {
116  return 255;
117  }
118 
119  if(isOnLine(x, z-4.0f, 0.125f, 5, 1))
120  {
121  return 255;
122  }
123  if(isOnLine(x, z-5.0f, 0.0625f, 5, 1))
124  {
125  return 255;
126  }
127 
128  // X direction
129  if(isOnLine(z, y-2.0f, 0.5f, 5, 0))
130  {
131  return 255;
132  }
133 
134  if(isOnLine(z, y-3.0f, 0.25f, 5, 0))
135  {
136  return 255;
137  }
138 
139  if(isOnLine(z, y-4.0f, 0.125f, 5, 0))
140  {
141  return 255;
142  }
143  if(isOnLine(z, y-5.0f, 0.0625f, 5, 0))
144  {
145  return 255;
146  }
147 
148 
149  // Return nonzero if value is inside region
150  else if(x > 0 && x < mBounds(0)
151  && y > 0 && y < mBounds(1)
152  && z > 0 && z < mBounds(2))
153  {
154  return 10;
155  }
156  return 0;
157 }
158 } //namespace cx
QString qstring_cast(const T &val)
virtual unsigned char evaluate(const cx::Vector3D &p) const
virtual bool isOnLine(float x, float y, float thickness, int n_lines, int axis) const
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:63