35 #include <vtkCellArray.h> 36 #include <vtkColorSeries.h> 37 #include <vtkPolyData.h> 38 #include <vtkPolyDataWriter.h> 39 #include <vtkPointData.h> 40 #include <QDomDocument> 43 #include <vtkTransformTextureCoords.h> 44 #include <vtkTexture.h> 45 #include <vtkTextureMapToCylinder.h> 46 #include <vtkTextureMapToPlane.h> 47 #include <vtkTextureMapToSphere.h> 52 #include "vtkProperty.h" 53 #include "vtkImageData.h" 70 Data(uid, name), mVtkPolyData(polyData), mHasGlyph(false), mOrientationArray(
""), mColorArray(
""), mPatientModelService(patientModelService),
71 mSpaceProvider(spaceProvider), mTextureData(patientModelService)
74 mVtkPolyData = vtkPolyDataPtr::New();
77 mShowGlyph = shouldGlyphBeEnableByDefault();
96 return mProperties.
mRepresentation->getValue().toInt() == VTK_WIREFRAME;
106 this->
setName(QFileInfo(path).baseName());
114 mVtkPolyData = polyData;
115 mVtkPolyDataOriginal = mVtkPolyData;
116 mOrientationArrayList.clear();
117 mColorArrayList.clear();
122 for(
int k=0; k < mVtkPolyData->GetPointData()->GetNumberOfArrays(); k++)
124 num=mVtkPolyData->GetPointData()->GetArray(k)->GetNumberOfComponents();
127 if(strlen(mOrientationArray.c_str())==0)
129 mOrientationArray=mVtkPolyData->GetPointData()->GetArrayName(k);
132 mOrientationArrayList << mVtkPolyData->GetPointData()->GetArrayName(k);
135 mColorArrayList <<
"";
137 for(
int k=0; k < mVtkPolyData->GetPointData()->GetNumberOfArrays(); k++)
139 num=mVtkPolyData->GetPointData()->GetArray(k)->GetNumberOfComponents();
142 mColorArrayList << mVtkPolyData->GetPointData()->GetArrayName(k);
146 mShowGlyph = shouldGlyphBeEnableByDefault();
163 QDomDocument doc = dataNode.ownerDocument();
165 QDomNode meshNode = dataNode;
167 mProperties.
addXml(dataNode);
168 mTextureData.
addXml(dataNode);
170 QDomElement glyphNode = doc.createElement(
"glyph");
171 QDomElement elemGlyph = glyphNode.toElement();
172 elemGlyph.setAttribute(
"showGlyph", mShowGlyph);
173 elemGlyph.setAttribute(
"orientationArray", mOrientationArray.c_str());
174 elemGlyph.setAttribute(
"colorArray", mColorArray.c_str());
175 elemGlyph.setAttribute(
"glyphLUT", mGlyphLUT.c_str());
176 meshNode.appendChild(elemGlyph);
187 if (dataNode.isNull())
193 QDomNode glyphNode = dataNode.namedItem(
"glyph");
194 if (!glyphNode.isNull())
196 mShowGlyph = glyphNode.toElement().attribute(
"showGlyph").toInt();
197 mOrientationArray = glyphNode.toElement().attribute(
"orientationArray").toStdString();
198 mColorArray = glyphNode.toElement().attribute(
"colorArray").toStdString();
199 mGlyphLUT = glyphNode.toElement().attribute(
"glyphLUT").toStdString();
207 mProperties.
mColor->setValue(color);
212 return mProperties.
mColor->getValue();
262 bool Mesh::shouldGlyphBeEnableByDefault()
264 if(! mHasGlyph)
return false;
265 if(!mVtkPolyData)
return false;
266 if(mVtkPolyData->GetNumberOfVerts() > 0)
return false;
267 if(mVtkPolyData->GetNumberOfLines() > 0)
return false;
268 if(mVtkPolyData->GetNumberOfPolys() > 0)
return false;
269 if(mVtkPolyData->GetNumberOfStrips() > 0)
return false;
277 return mOrientationArray.c_str();
282 mOrientationArray = orientationArray;
288 return mProperties.
mVisSize->getValue();
293 mProperties.
mVisSize->setValue(size);
298 return mColorArray.c_str();
303 mColorArray = colorArray;
309 return mGlyphLUT.c_str();
319 mGlyphLUT = glyphLUT;
336 if(mVtkPolyDataOriginal)
337 mVtkPolyData = mVtkPolyDataOriginal;
343 if(!this->createTextureMapper(tMapper))
351 mVtkTexture = vtkTexturePtr::New();
352 mVtkTexture->SetRepeat(mTextureData.
getRepeat()->getValue());
353 mVtkTexture->SetInputData(vtkImageData);
359 transformTexture->SetInputConnection(tMapper->GetOutputPort());
362 transformTexture->SetPosition(-posR, -posS, 0);
365 transformTexture->SetScale(scaleR, scaleS, 1);
366 transformTexture->Update();
369 mVtkPolyData = transformTexture->GetPolyDataOutput();
378 tMapper = vtkTextureMapToCylinderPtr::New();
379 dynamic_cast<vtkTextureMapToCylinder*
>(tMapper.Get())->PreventSeamOn();
387 mapper->SetOrigin(bb.
corner(0,0,1).data());
388 mapper->SetPoint1(bb.
corner(1,0,1).data());
389 mapper->SetPoint2(bb.
corner(0,1,1).data());
395 tMapper = vtkTextureMapToSpherePtr::New();
402 tMapper->SetInputData(mVtkPolyData);
408 return mOrientationArrayList;
413 return mColorArrayList;
436 if (
similar(transform, Transform3D::Identity()))
448 floatPoints->DeepCopy(points);
449 floatPoints->SetDataTypeToFloat();
450 for (
int i = 0; i < poly->GetNumberOfPoints(); ++i)
453 p = transform.coord(p);
454 floatPoints->SetPoint(i, p.begin());
456 poly->SetPoints(floatPoints.GetPointer());
465 return poly->GetLines()->GetNumberOfCells() > 0 && poly->GetPolys()->GetNumberOfCells() == 0 && poly->GetStrips()->GetNumberOfCells() == 0;
472 QString filename = basePath +
"/Images/" + this->
getUid() +
".vtk";
473 this->
setFilename(QDir(basePath).relativeFilePath(filename));
virtual DoubleBoundingBox3D boundingBox() const
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
vtkSmartPointer< class vtkTexture > vtkTexturePtr
BoolPropertyBasePtr mUseColorFromPolydataScalars
DoubleBoundingBox3D transform(const Transform3D &m, const DoubleBoundingBox3D &bb)
Vector3D corner(int x, int y, int z) const
DoublePropertyPtr mVisSize
const char * getOrientationArray()
Mesh(const QString &uid, const QString &name="", vtkPolyDataPtr polyData=vtkPolyDataPtr(), PatientModelServicePtr patientModelService=PatientModelService::getNullObject(), SpaceProviderPtr spaceProvider=SpaceProvider::getNullObject())
bool isFiberBundle() const
void parseXml(QDomNode dataNode)
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
vtkSmartPointer< class vtkDataSetAlgorithm > vtkDataSetAlgorithmPtr
void parseXml(QDomNode &dataNode)
BoolPropertyPtr mFrontfaceCulling
void setVisSize(double size)
boost::shared_ptr< class Image > ImagePtr
void setName(const QString &name)
virtual vtkPolyDataPtr getVtkPolyData() const
vtkSmartPointer< vtkPoints > vtkPointsPtr
virtual bool load(QString path)
cstring_cast_Placeholder cstring_cast(const T &val)
void updateVtkPolyDataWithTexture()
void setFrontfaceCullingSlot(bool backfaceCulling)
Set frontface culling on/off in mesh visualization.
QStringList getColorArrayList()
virtual void addXml(QDomNode &dataNode)
adds xml information about the data and its variabels
vtkSmartPointer< class vtkTransformTextureCoords > vtkTransformTextureCoordsPtr
vtkSmartPointer< class vtkTextureMapToPlane > vtkTextureMapToPlanePtr
QString getTextureShape()
DoublePropertyPtr getPositionY() const
QString getPlaneText() const
virtual QString getUid() const
DoublePropertyPtr getScaleX() const
vtkPolyDataPtr loadVtkPolyData(QString filename)
StringPropertySelectImagePtr getTextureImage() const
bool getIsWireframe() const
true=wireframe, false=surface
DoublePropertyPtr getPositionX() const
StringPropertyPtr mRepresentation
static MeshPtr create(const QString &uid, const QString &name="", PatientModelServicePtr patientModelService=PatientModelService::getNullObject(), SpaceProviderPtr spaceProvider=SpaceProvider::getNullObject())
QString getSphereText() const
void setBackfaceCullingSlot(bool backfaceCulling)
Set backface culling on/off in mesh visualization.
BoolPropertyPtr getRepeat() const
void setVtkPolyData(const vtkPolyDataPtr &polyData)
virtual void parseXml(QDomNode &dataNode)
Use a XML node to load data.
bool getBackfaceCulling()
Get backface culling.
void setOrientationArray(const char *orientationArray)
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
void setAcquisitionTime(QDateTime time)
BoolPropertyPtr mBackfaceCulling
Read or write vtk or ssc data objects from/to file.
void addXml(QDomNode &dataNode)
vtkSmartPointer< class vtkPolyDataWriter > vtkPolyDataWriterPtr
Representation of a floating-point bounding box in 3D. The data are stored as {xmin,xmax,ymin,ymax,zmin,zmax}, in order to simplify communication with vtk.
void setIsWireframe(bool on)
Set rep to wireframe, false means surface.
void setUseColorFromPolydataScalars(bool on)
void setGlyphLUT(const char *glyphLUT)
const MeshTextureData & getTextureData() const
const char * getGlyphLUT()
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
virtual void save(const QString &basePath)
virtual void parseXml(QDomNode &dataNode)
Use a XML node to load data.
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
DoublePropertyPtr getScaleY() const
Superclass for all data objects.
QString getCylinderText() const
void addXml(QDomNode &dataNode)
adds xml information about the image and its variabels
bool similar(const CameraInfo &lhs, const CameraInfo &rhs, double tol)
void addXml(QDomNode &dataNode)
void setShowGlyph(bool val)
vtkPolyDataPtr getTransformedPolyDataCopy(Transform3D tranform)
Create a new transformed polydata.
bool getFrontfaceCulling()
Get frontface culling.
const MeshPropertyData & getProperties() const
void setColorArray(const char *colorArray)
boost::shared_ptr< class Mesh > MeshPtr
QStringList getOrientationArrayList()
virtual vtkTexturePtr getVtkTexture() const
StringPropertyPtr getTextureShape() const
const char * getColorArray()
virtual void setFilename(QString val)
bool getUseColorFromPolydataScalars() const
void setColor(const QColor &color)
Set the color of the mesh.
QColor getColor()
Get the color of the mesh (Values are range 0 - 255)
Namespace for all CustusX production code.