34 #include "vtkImageData.h" 48 double random_value_1 = (rand()+1.0)/(RAND_MAX+1.0);
49 double random_value_2 = (rand()+1.0)/(RAND_MAX+1.0);
51 double random_normal = sqrt(-2*log(random_value_1)) * cos(2*
M_PI*random_value_2);
53 return random_normal*noiseSigma + noiseMean;
63 const double noiseSigma,
64 const unsigned char noiseMean)
const 69 std::vector<Transform3D> planes_rMf(planes_rMt.size());
70 for (
unsigned i=0; i<planes_rMt.size(); ++i)
71 planes_rMf[i] = planes_rMt[i] * sector.
get_tMu() * sector.
get_uMv();
73 Eigen::Array2f pixelSpacing = probe.
getSpacing().block(0,0,2,1).cast<
float>();
74 Eigen::Array2i sliceDimension(probe.
getSize().width(), probe.
getSize().height());
80 noiseSigma, noiseMean);
86 const double noiseSigma,
87 const unsigned char noiseMean)
const 93 Eigen::Array2f pixelSpacing = probe.
getSpacing().block(0,0,2,1).cast<
float>();
94 Eigen::Array2i sliceDimension(probe.
getSize().width(), probe.
getSize().height());
99 noiseSigma, noiseMean);
104 const Eigen::Array2f& pixelSpacing,
105 const Eigen::Array2i& sliceDimension,
107 const double noiseSigma,
const unsigned char noiseMean)
const 109 std::vector<TimedPosition> positions;
110 std::vector<vtkImageDataPtr> images;
112 for(std::vector<Transform3D>::const_iterator i = planes_rMf.begin();
113 planes_rMf.end() != i;
119 us_frame = this->
sampleUsData(rMf, pixelSpacing, sliceDimension, noiseSigma, noiseMean);
123 t.
mTime = i - planes_rMf.begin();
124 t.
mPos = output_dMr*rMf;
126 positions.push_back(t);
127 images.push_back(us_frame);
140 const Eigen::Array2f& pixelSpacing,
141 const Eigen::Array2i& sliceDimension,
142 const double noiseSigma,
const unsigned char noiseMean)
const 151 us_frame->SetExtent(0, sliceDimension[0]-1, 0, sliceDimension[1]-1, 0, 0);
152 us_frame->SetSpacing(pixelSpacing[0], pixelSpacing[1], 0.0);
153 us_frame->AllocateScalars(VTK_UNSIGNED_CHAR, 1);
155 unsigned char* us_data = (
unsigned char*)us_frame->GetScalarPointer();
157 for(
unsigned int px = 0; px < sliceDimension[0]; px++)
160 const Vector3D px0_vol = p0 + e_x*px;
162 for(
unsigned int py = 0; py < sliceDimension[1]; py++)
164 const Vector3D volume_coords = px0_vol + e_y*py;
167 const unsigned char val = this->
evaluate(volume_coords);
169 const double noise_val =
noiseValue(noiseSigma, noiseMean);
170 const int noised_val = noise_val + val;
173 us_data[px + py*sliceDimension[0]] = final_val;
185 mask->SetExtent(0, sliceDimension[0]-1, 0, sliceDimension[1]-1, 0, 0);
186 mask->AllocateScalars(VTK_UNSIGNED_CHAR, 1);
187 unsigned char* mask_data = (
unsigned char*)mask->GetScalarPointer();
188 memset(mask_data, 1,
sizeof(
unsigned char)*sliceDimension[0]*sliceDimension[1]);
205 return (
unsigned char)val;
214 nominal->DeepCopy(input);
216 nominal_img->get_rMd_History()->setRegistration(vol->get_rMd());
227 Eigen::Array3i dims = Eigen::Array3i(raw->GetDimensions());
228 Eigen::Array3d spacing = Eigen::Array3d(raw->GetSpacing());
229 unsigned char *pixels = (
unsigned char*)raw->GetScalarPointer();
231 for(
int z = 0; z < dims[2]; ++z)
233 for(
int y = 0; y < dims[1]; ++y)
235 for(
int x = 0; x < dims[0]; ++x)
238 int index = x + y*dims[0] + z*dims[1]*dims[0];
239 pixels[index] = this->
evaluate(rMd.coord(p_d));
248 CX_ASSERT(Eigen::Array3i(a->GetDimensions()).isApprox(Eigen::Array3i(b->GetDimensions())));
249 CX_ASSERT(Eigen::Array3d(a->GetSpacing()).isApprox(Eigen::Array3d(b->GetSpacing())));
252 Eigen::Array3i dims = Eigen::Array3i(a->GetDimensions());
253 unsigned char *pa = (
unsigned char*)a->GetScalarPointer();
254 unsigned char *pb = (
unsigned char*)b->GetScalarPointer();
256 for(
int z = 0; z < dims[2]; ++z)
258 for(
int y = 0; y < dims[1]; ++y)
260 for(
int x = 0; x < dims[0]; ++x)
262 int index = x + y*dims[0] + z*dims[1]*dims[0];
263 float error = pa[index] - pb[index];
269 return sqrt(sse/dims.prod());
285 if (*val < mThreshold)
297 unsigned char mThreshold;
308 mWeight = Vector3D::Zero();
314 if (*val < mThreshold)
317 mWeight +=
Vector3D(x,y,z) * (*val);
328 unsigned char mThreshold;
331 template<
class FUNCTOR>
335 Eigen::Array3i dims = Eigen::Array3i(raw->GetDimensions());
336 unsigned char *pixels = (
unsigned char*)raw->GetScalarPointer();
338 for(
int z = 0; z < dims[2]; ++z)
340 for(
int y = 0; y < dims[1]; ++y)
342 for(
int x = 0; x < dims[0]; ++x)
344 int index = x + y*dims[0] + z*dims[1]*dims[0];
345 func(x,y,z, pixels+index);
355 Eigen::Array3d spacing = Eigen::Array3d(raw->GetSpacing());
359 Vector3D ci = func.getCentroid().array() * spacing;
360 return rMd.coord(ci);
void fillVolume(cx::ImagePtr vol)
#define CX_ASSERT(statement)
One position with timestamp.
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
double calculateMass(cx::ImagePtr image)
boost::shared_ptr< class Image > ImagePtr
void operator()(int x, int y, int z, unsigned char *val)
virtual unsigned char evaluate(const Vector3D &p) const =0
void applyFunctor(cx::ImagePtr image, FUNCTOR &func)
cx::Vector3D calculateCentroid(cx::ImagePtr image)
Transform3D get_uMv() const
get transform from inverted image space v (origin in ul corner) to image space u. ...
double calculateRMSError(vtkImageDataPtr a, vtkImageDataPtr b)
Transform3D get_tMu() const
get transform from image space u to probe tool space t.
virtual ProcessedUSInputDataPtr sampleUsData(const std::vector< Transform3D > &planes_rMf, const Eigen::Array2f &pixelSpacing, const Eigen::Array2i &sliceDimension, const Transform3D &output_dMr, const double noiseSigma, const unsigned char noiseMean) const
unsigned char constrainToUnsignedChar(const int val) const
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition of characteristics for an Ultrasound Probe Sector.
Vector3D getSpacing() const
double noiseValue(double noiseSigma, double noiseMean)
void setDeepModified(vtkImageDataPtr image)
vtkImageDataPtr createEmptyMask(const Eigen::Array2i &sliceDimension) const
Utility functions for drawing an US Probe sector.
virtual float computeRMSError(cx::ImagePtr vol)
boost::shared_ptr< class ProcessedUSInputData > ProcessedUSInputDataPtr
void setData(ProbeDefinition data)
Namespace for all CustusX production code.
void operator()(int x, int y, int z, unsigned char *val)