14 #include <vtkCellArray.h> 15 #include <vtkColorSeries.h> 16 #include <vtkPolyData.h> 17 #include <vtkPolyDataWriter.h> 18 #include <vtkPointData.h> 19 #include <QDomDocument> 22 #include <vtkTransformTextureCoords.h> 23 #include <vtkTexture.h> 24 #include <vtkTextureMapToCylinder.h> 25 #include <vtkTextureMapToPlane.h> 26 #include <vtkTextureMapToSphere.h> 31 #include "vtkProperty.h" 32 #include "vtkImageData.h" 49 Data(uid, name), mVtkPolyData(polyData), mHasGlyph(false), mOrientationArray(
""), mColorArray(
""), mPatientModelService(patientModelService),
50 mSpaceProvider(spaceProvider), mTextureData(patientModelService)
53 mVtkPolyData = vtkPolyDataPtr::New();
56 mShowGlyph = shouldGlyphBeEnableByDefault();
75 return mProperties.
mRepresentation->getValue().toInt() == VTK_WIREFRAME;
85 this->
setName(QFileInfo(path).baseName());
93 mVtkPolyData = polyData;
94 mVtkPolyDataOriginal = mVtkPolyData;
95 mOrientationArrayList.clear();
96 mColorArrayList.clear();
101 for(
int k=0; k < mVtkPolyData->GetPointData()->GetNumberOfArrays(); k++)
103 num=mVtkPolyData->GetPointData()->GetArray(k)->GetNumberOfComponents();
106 if(strlen(mOrientationArray.c_str())==0)
108 mOrientationArray=mVtkPolyData->GetPointData()->GetArrayName(k);
111 mOrientationArrayList << mVtkPolyData->GetPointData()->GetArrayName(k);
114 mColorArrayList <<
"";
116 for(
int k=0; k < mVtkPolyData->GetPointData()->GetNumberOfArrays(); k++)
118 num=mVtkPolyData->GetPointData()->GetArray(k)->GetNumberOfComponents();
121 mColorArrayList << mVtkPolyData->GetPointData()->GetArrayName(k);
125 mShowGlyph = shouldGlyphBeEnableByDefault();
142 QDomDocument doc = dataNode.ownerDocument();
144 QDomNode meshNode = dataNode;
146 mProperties.
addXml(dataNode);
147 mTextureData.
addXml(dataNode);
149 QDomElement glyphNode = doc.createElement(
"glyph");
150 QDomElement elemGlyph = glyphNode.toElement();
151 elemGlyph.setAttribute(
"showGlyph", mShowGlyph);
152 elemGlyph.setAttribute(
"orientationArray", mOrientationArray.c_str());
153 elemGlyph.setAttribute(
"colorArray", mColorArray.c_str());
154 elemGlyph.setAttribute(
"glyphLUT", mGlyphLUT.c_str());
155 meshNode.appendChild(elemGlyph);
166 if (dataNode.isNull())
172 QDomNode glyphNode = dataNode.namedItem(
"glyph");
173 if (!glyphNode.isNull())
175 mShowGlyph = glyphNode.toElement().attribute(
"showGlyph").toInt();
176 mOrientationArray = glyphNode.toElement().attribute(
"orientationArray").toStdString();
177 mColorArray = glyphNode.toElement().attribute(
"colorArray").toStdString();
178 mGlyphLUT = glyphNode.toElement().attribute(
"glyphLUT").toStdString();
186 mProperties.
mColor->setValue(color);
191 return mProperties.
mColor->getValue();
241 bool Mesh::shouldGlyphBeEnableByDefault()
243 if(! mHasGlyph)
return false;
244 if(!mVtkPolyData)
return false;
245 if(mVtkPolyData->GetNumberOfVerts() > 0)
return false;
246 if(mVtkPolyData->GetNumberOfLines() > 0)
return false;
247 if(mVtkPolyData->GetNumberOfPolys() > 0)
return false;
248 if(mVtkPolyData->GetNumberOfStrips() > 0)
return false;
256 return mOrientationArray.c_str();
261 mOrientationArray = orientationArray;
267 return mProperties.
mVisSize->getValue();
272 mProperties.
mVisSize->setValue(size);
277 return mColorArray.c_str();
282 mColorArray = colorArray;
288 return mGlyphLUT.c_str();
298 mGlyphLUT = glyphLUT;
315 if(mVtkPolyDataOriginal)
316 mVtkPolyData = mVtkPolyDataOriginal;
322 if(!this->createTextureMapper(tMapper))
330 mVtkTexture = vtkTexturePtr::New();
331 mVtkTexture->SetRepeat(mTextureData.
getRepeat()->getValue());
332 mVtkTexture->SetInputData(vtkImageData);
338 transformTexture->SetInputConnection(tMapper->GetOutputPort());
341 transformTexture->SetPosition(-posR, -posS, 0);
344 transformTexture->SetScale(scaleR, scaleS, 1);
345 transformTexture->Update();
348 mVtkPolyData = transformTexture->GetPolyDataOutput();
357 tMapper = vtkTextureMapToCylinderPtr::New();
358 dynamic_cast<vtkTextureMapToCylinder*
>(tMapper.Get())->PreventSeamOn();
366 mapper->SetOrigin(bb.
corner(0,0,1).data());
367 mapper->SetPoint1(bb.
corner(1,0,1).data());
368 mapper->SetPoint2(bb.
corner(0,1,1).data());
374 tMapper = vtkTextureMapToSpherePtr::New();
381 tMapper->SetInputData(mVtkPolyData);
387 return mOrientationArrayList;
392 return mColorArrayList;
415 if (
similar(transform, Transform3D::Identity()))
427 floatPoints->DeepCopy(points);
428 floatPoints->SetDataTypeToFloat();
429 for (
int i = 0; i < poly->GetNumberOfPoints(); ++i)
432 p = transform.coord(p);
433 floatPoints->SetPoint(i, p.begin());
435 poly->SetPoints(floatPoints.GetPointer());
444 return poly->GetLines()->GetNumberOfCells() > 0 && poly->GetPolys()->GetNumberOfCells() == 0 && poly->GetStrips()->GetNumberOfCells() == 0;
451 QString filename = basePath +
"/Images/" + this->
getUid() +
".vtk";
452 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.