7 #include "imstkImageData.h" 8 #include "imstkLogger.h" 9 #include "imstkVecDataArray.h" 17 LOG(INFO) <<
"Scalar Type: " <<
static_cast<int>(m_scalarArray->getScalarType());
18 LOG(INFO) <<
"Number of Components" << m_numComps;
19 LOG(INFO) <<
"Dimensions: " << m_dims[0] <<
", " << m_dims[1] <<
", " << m_dims[2];
20 LOG(INFO) <<
"Spacing: " << m_spacing[0] <<
", " << m_spacing[1] <<
", " << m_spacing[2];
21 LOG(INFO) <<
"Origin: " << m_origin[0] <<
", " << m_origin[1] <<
", " << m_origin[2];
22 LOG(INFO) <<
"Bounds: ";
23 LOG(INFO) <<
"\t" << m_bounds[0] <<
", " << m_bounds[1];
24 LOG(INFO) <<
"\t" << m_bounds[2] <<
", " << m_bounds[3];
25 LOG(INFO) <<
"\t" << m_bounds[4] <<
", " << m_bounds[5];
31 return (m_dims[0] * m_spacing.x()) *
32 (m_dims[1] * m_spacing.y()) *
33 (m_dims[2] * m_spacing.z());
39 return m_scalarArray->getVoidPointer();
42 std::shared_ptr<ImageData>
43 ImageData::cast(ScalarTypeId toType)
46 std::shared_ptr<ImageData> results = std::make_shared<ImageData>();
47 results->setOrigin(m_origin);
48 results->setSpacing(m_spacing);
49 results->setScalars(
getScalars()->cast(toType), m_numComps, m_dims.data());
56 return m_scalarArray->getScalarType();
60 ImageData::setScalars(std::shared_ptr<AbstractDataArray> scalars,
const int numComps,
int* dim)
62 CHECK(scalars !=
nullptr);
63 if (dim[0] * dim[1] * dim[2] * numComps != scalars->size())
65 LOG(WARNING) <<
"Scalars don't align";
67 m_scalarArray = scalars;
71 m_numComps = numComps;
75 ImageData::allocate(
const ScalarTypeId type,
const int numComps,
const Vec3i& dims,
const Vec3d& spacing,
const Vec3d& origin)
80 m_numComps = numComps;
81 const int numVals = dims[0] * dims[1] * dims[2];
86 LOG(WARNING) <<
"Tried to allocate unknown scalar type";
95 std::shared_ptr<VecDataArray<double, 3>> vertices =
96 std::make_shared<VecDataArray<double, 3>>(m_dims[0] * m_dims[1] * m_dims[2]);
98 const Vec3d shift = m_origin + m_spacing * 0.5;
100 for (
int z = 0; z < m_dims[2]; z++)
102 for (
int y = 0; y < m_dims[1]; y++)
104 for (
int x = 0; x < m_dims[0]; x++, i++)
106 vertexData[i] = Vec3d(x, y, z).cwiseProduct(m_spacing) + shift;
117 if (this->m_scalarArray !=
nullptr)
119 this->m_scalarArray =
nullptr;
126 ImageData::cloneImplementation()
const 130 geom->m_scalarArray = m_scalarArray->clone();
virtual void print() const override
Print the mesh info.
const ScalarTypeId getScalarType() const
Returns the scalar type of the image.
void allocate(const ScalarTypeId type, const int numComps, const Vec3i &dims, const Vec3d &spacing=Vec3d(1.0, 1.0, 1.0), const Vec3d &origin=Vec3d(0.0, 0.0, 0.0))
Allocate image by type.
void postModified()
Post modified event.
double getVolume() override
Returns the volume.
void computePoints()
Generates points in the geometry from the ImageData (center of each voxel)
std::shared_ptr< AbstractDataArray > getScalars() const
Get/Set the scalars.
void setInitialVertexPositions(std::shared_ptr< VecDataArray< double, 3 >> vertices)
Sets initial positions from an array.
void clear() override
Clear the data.
void setVertexPositions(std::shared_ptr< VecDataArray< double, 3 >> positions)
Sets current vertex positions of the mesh.
void print() const override
Print the image data info.
Simple dynamic array implementation that also supports event posting and viewing/facade.
Class to represent 1, 2, or 3D image data (i.e. structured points)
void * getVoidPointer()
Returns a pointer to the underlying storage of the image.