13 #include "vtkImageData.h" 27 double random_value_1 = (rand()+1.0)/(RAND_MAX+1.0);
28 double random_value_2 = (rand()+1.0)/(RAND_MAX+1.0);
30 double random_normal = sqrt(-2*log(random_value_1)) * cos(2*
M_PI*random_value_2);
32 return random_normal*noiseSigma + noiseMean;
42 const double noiseSigma,
43 const unsigned char noiseMean)
const 48 std::vector<Transform3D> planes_rMf(planes_rMt.size());
49 for (
unsigned i=0; i<planes_rMt.size(); ++i)
50 planes_rMf[i] = planes_rMt[i] * sector.
get_tMu() * sector.
get_uMv();
52 Eigen::Array2f pixelSpacing = probe.
getSpacing().block(0,0,2,1).cast<
float>();
53 Eigen::Array2i sliceDimension(probe.
getSize().width(), probe.
getSize().height());
59 noiseSigma, noiseMean);
65 const double noiseSigma,
66 const unsigned char noiseMean)
const 72 Eigen::Array2f pixelSpacing = probe.
getSpacing().block(0,0,2,1).cast<
float>();
73 Eigen::Array2i sliceDimension(probe.
getSize().width(), probe.
getSize().height());
78 noiseSigma, noiseMean);
83 const Eigen::Array2f& pixelSpacing,
84 const Eigen::Array2i& sliceDimension,
86 const double noiseSigma,
const unsigned char noiseMean)
const 88 std::vector<TimedPosition> positions;
89 std::vector<vtkImageDataPtr> images;
91 for(std::vector<Transform3D>::const_iterator i = planes_rMf.begin();
92 planes_rMf.end() != i;
98 us_frame = this->
sampleUsData(rMf, pixelSpacing, sliceDimension, noiseSigma, noiseMean);
102 t.
mTime = i - planes_rMf.begin();
103 t.
mPos = output_dMr*rMf;
105 positions.push_back(t);
106 images.push_back(us_frame);
119 const Eigen::Array2f& pixelSpacing,
120 const Eigen::Array2i& sliceDimension,
121 const double noiseSigma,
const unsigned char noiseMean)
const 130 us_frame->SetExtent(0, sliceDimension[0]-1, 0, sliceDimension[1]-1, 0, 0);
131 us_frame->SetSpacing(pixelSpacing[0], pixelSpacing[1], 0.0);
132 us_frame->AllocateScalars(VTK_UNSIGNED_CHAR, 1);
134 unsigned char* us_data = (
unsigned char*)us_frame->GetScalarPointer();
136 for(
unsigned int px = 0; px < sliceDimension[0]; px++)
139 const Vector3D px0_vol = p0 + e_x*px;
141 for(
unsigned int py = 0; py < sliceDimension[1]; py++)
143 const Vector3D volume_coords = px0_vol + e_y*py;
146 const unsigned char val = this->
evaluate(volume_coords);
148 const double noise_val =
noiseValue(noiseSigma, noiseMean);
149 const int noised_val = noise_val + val;
152 us_data[px + py*sliceDimension[0]] = final_val;
164 mask->SetExtent(0, sliceDimension[0]-1, 0, sliceDimension[1]-1, 0, 0);
165 mask->AllocateScalars(VTK_UNSIGNED_CHAR, 1);
166 unsigned char* mask_data = (
unsigned char*)mask->GetScalarPointer();
167 memset(mask_data, 1,
sizeof(
unsigned char)*sliceDimension[0]*sliceDimension[1]);
184 return (
unsigned char)val;
193 nominal->DeepCopy(input);
195 nominal_img->get_rMd_History()->setRegistration(vol->get_rMd());
206 Eigen::Array3i dims = Eigen::Array3i(raw->GetDimensions());
207 Eigen::Array3d spacing = Eigen::Array3d(raw->GetSpacing());
208 unsigned char *pixels = (
unsigned char*)raw->GetScalarPointer();
210 for(
int z = 0; z < dims[2]; ++z)
212 for(
int y = 0; y < dims[1]; ++y)
214 for(
int x = 0; x < dims[0]; ++x)
217 int index = x + y*dims[0] + z*dims[1]*dims[0];
218 pixels[index] = this->
evaluate(rMd.coord(p_d));
227 CX_ASSERT(Eigen::Array3i(a->GetDimensions()).isApprox(Eigen::Array3i(b->GetDimensions())));
228 CX_ASSERT(Eigen::Array3d(a->GetSpacing()).isApprox(Eigen::Array3d(b->GetSpacing())));
231 Eigen::Array3i dims = Eigen::Array3i(a->GetDimensions());
232 unsigned char *pa = (
unsigned char*)a->GetScalarPointer();
233 unsigned char *pb = (
unsigned char*)b->GetScalarPointer();
235 for(
int z = 0; z < dims[2]; ++z)
237 for(
int y = 0; y < dims[1]; ++y)
239 for(
int x = 0; x < dims[0]; ++x)
241 int index = x + y*dims[0] + z*dims[1]*dims[0];
242 float error = pa[index] - pb[index];
248 return sqrt(sse/dims.prod());
264 if (*val < mThreshold)
276 unsigned char mThreshold;
287 mWeight = Vector3D::Zero();
293 if (*val < mThreshold)
296 mWeight +=
Vector3D(x,y,z) * (*val);
307 unsigned char mThreshold;
310 template<
class FUNCTOR>
314 Eigen::Array3i dims = Eigen::Array3i(raw->GetDimensions());
315 unsigned char *pixels = (
unsigned char*)raw->GetScalarPointer();
317 for(
int z = 0; z < dims[2]; ++z)
319 for(
int y = 0; y < dims[1]; ++y)
321 for(
int x = 0; x < dims[0]; ++x)
323 int index = x + y*dims[0] + z*dims[1]*dims[0];
324 func(x,y,z, pixels+index);
334 Eigen::Array3d spacing = Eigen::Array3d(raw->GetSpacing());
338 Vector3D ci = func.getCentroid().array() * spacing;
339 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)