14 #include <vtkCellArray.h> 15 #include <vtkColorSeries.h> 16 #include <vtkPolyData.h> 17 #include <vtkPointData.h> 18 #include <QDomDocument> 21 #include <vtkTransformTextureCoords.h> 22 #include <vtkTexture.h> 23 #include <vtkTextureMapToCylinder.h> 24 #include <vtkTextureMapToPlane.h> 25 #include <vtkTextureMapToSphere.h> 29 #include "vtkProperty.h" 30 #include "vtkImageData.h" 50 Data(uid, name), mVtkPolyData(polyData), mHasGlyph(false), mOrientationArray(
""), mColorArray(
""), mPatientModelService(patientModelService),
51 mSpaceProvider(spaceProvider), mTextureData(patientModelService)
54 mVtkPolyData = vtkPolyDataPtr::New();
57 mShowGlyph = shouldGlyphBeEnableByDefault();
76 return mProperties.
mRepresentation->getValue().toInt() == VTK_WIREFRAME;
82 raw = filemanager->loadVtkPolyData(path);
86 this->
setName(QFileInfo(path).baseName());
94 mVtkPolyData = polyData;
95 mVtkPolyDataOriginal = mVtkPolyData;
96 mOrientationArrayList.clear();
97 mColorArrayList.clear();
102 for(
int k=0; k < mVtkPolyData->GetPointData()->GetNumberOfArrays(); k++)
104 num=mVtkPolyData->GetPointData()->GetArray(k)->GetNumberOfComponents();
107 if(strlen(mOrientationArray.c_str())==0)
109 mOrientationArray=mVtkPolyData->GetPointData()->GetArrayName(k);
112 mOrientationArrayList << mVtkPolyData->GetPointData()->GetArrayName(k);
115 mColorArrayList <<
"";
117 for(
int k=0; k < mVtkPolyData->GetPointData()->GetNumberOfArrays(); k++)
119 num=mVtkPolyData->GetPointData()->GetArray(k)->GetNumberOfComponents();
122 mColorArrayList << mVtkPolyData->GetPointData()->GetArrayName(k);
126 mShowGlyph = shouldGlyphBeEnableByDefault();
143 QDomDocument doc = dataNode.ownerDocument();
145 QDomNode meshNode = dataNode;
147 mProperties.
addXml(dataNode);
148 mTextureData.
addXml(dataNode);
150 QDomElement glyphNode = doc.createElement(
"glyph");
151 QDomElement elemGlyph = glyphNode.toElement();
152 elemGlyph.setAttribute(
"showGlyph", mShowGlyph);
153 elemGlyph.setAttribute(
"orientationArray", mOrientationArray.c_str());
154 elemGlyph.setAttribute(
"colorArray", mColorArray.c_str());
155 elemGlyph.setAttribute(
"glyphLUT", mGlyphLUT.c_str());
156 meshNode.appendChild(elemGlyph);
167 if (dataNode.isNull())
173 QDomNode glyphNode = dataNode.namedItem(
"glyph");
174 if (!glyphNode.isNull())
176 mShowGlyph = glyphNode.toElement().attribute(
"showGlyph").toInt();
177 mOrientationArray = glyphNode.toElement().attribute(
"orientationArray").toStdString();
178 mColorArray = glyphNode.toElement().attribute(
"colorArray").toStdString();
179 mGlyphLUT = glyphNode.toElement().attribute(
"glyphLUT").toStdString();
187 mProperties.
mColor->setValue(color);
192 return mProperties.
mColor->getValue();
242 bool Mesh::shouldGlyphBeEnableByDefault()
244 if(! mHasGlyph)
return false;
245 if(!mVtkPolyData)
return false;
246 if(mVtkPolyData->GetNumberOfVerts() > 0)
return false;
247 if(mVtkPolyData->GetNumberOfLines() > 0)
return false;
248 if(mVtkPolyData->GetNumberOfPolys() > 0)
return false;
249 if(mVtkPolyData->GetNumberOfStrips() > 0)
return false;
257 return mOrientationArray.c_str();
262 mOrientationArray = orientationArray;
268 return mProperties.
mVisSize->getValue();
273 mProperties.
mVisSize->setValue(size);
278 return mColorArray.c_str();
283 mColorArray = colorArray;
289 return mGlyphLUT.c_str();
299 mGlyphLUT = glyphLUT;
316 if(mVtkPolyDataOriginal)
317 mVtkPolyData = mVtkPolyDataOriginal;
323 if(!this->createTextureMapper(tMapper))
331 mVtkTexture = vtkTexturePtr::New();
332 mVtkTexture->SetRepeat(mTextureData.
getRepeat()->getValue());
333 mVtkTexture->SetInputData(vtkImageData);
339 transformTexture->SetInputConnection(tMapper->GetOutputPort());
342 transformTexture->SetPosition(-posR, -posS, 0);
345 transformTexture->SetScale(scaleR, scaleS, 1);
346 transformTexture->Update();
349 mVtkPolyData = transformTexture->GetPolyDataOutput();
358 tMapper = vtkTextureMapToCylinderPtr::New();
359 dynamic_cast<vtkTextureMapToCylinder*
>(tMapper.Get())->PreventSeamOn();
367 mapper->SetOrigin(bb.
corner(0,0,1).data());
368 mapper->SetPoint1(bb.
corner(1,0,1).data());
369 mapper->SetPoint2(bb.
corner(0,1,1).data());
375 tMapper = vtkTextureMapToSpherePtr::New();
382 tMapper->SetInputData(mVtkPolyData);
388 return mOrientationArrayList;
393 return mColorArrayList;
416 if (
similar(transform, Transform3D::Identity()))
428 floatPoints->DeepCopy(points);
429 floatPoints->SetDataTypeToFloat();
430 for (
int i = 0; i < poly->GetNumberOfPoints(); ++i)
433 p = transform.coord(p);
434 floatPoints->SetPoint(i, p.begin());
436 poly->SetPoints(floatPoints.GetPointer());
445 return poly->GetLines()->GetNumberOfCells() > 0 && poly->GetPolys()->GetNumberOfCells() == 0 && poly->GetStrips()->GetNumberOfCells() == 0;
450 QString filename = basePath +
"/Images/" + this->
getUid() +
".vtk";
451 this->
setFilename(QDir(basePath).relativeFilePath(filename));
453 fileManager->save(
self, filename);
virtual DoubleBoundingBox3D boundingBox() const
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
vtkSmartPointer< class vtkTexture > vtkTexturePtr
BoolPropertyBasePtr mUseColorFromPolydataScalars
boost::shared_ptr< class FileManagerService > FileManagerServicePtr
virtual bool load(QString path, FileManagerServicePtr filemanager)
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
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
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.
virtual void save(const QString &basePath, FileManagerServicePtr fileManager)
void setOrientationArray(const char *orientationArray)
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
void setAcquisitionTime(QDateTime time)
BoolPropertyPtr mBackfaceCulling
void addXml(QDomNode &dataNode)
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 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.