CustusX  2023.01.05-dev+develop.0da12
An IGT application
cxMeshTextureData.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 
13 #include "cxMeshTextureData.h"
14 #include "cxDoubleProperty.h"
15 #include "cxBoolProperty.h"
16 
17 namespace cx
18 {
20  : mPatientModelService(patientModelService)
21  , mCylinderText("Cylinder")
22  , mPlaneText("Plane")
23  , mSphereText("Sphere")
24 {
25  this->initialize();
26 }
27 
28 void MeshTextureData::addXml(QDomNode &dataNode)
29 {
30  for (unsigned i=0; i<mProperties.size(); ++i)
31  {
32  XmlOptionItem item(mProperties[i]->getUid(), dataNode.toElement());
33  item.writeVariant(mProperties[i]->getValueAsVariant());
34  }
35 }
36 
37 void MeshTextureData::parseXml(QDomNode &dataNode)
38 {
39  for (unsigned i=0; i<mProperties.size(); ++i)
40  {
41  XmlOptionItem item(mProperties[i]->getUid(), dataNode.toElement());
42  QVariant orgval = mProperties[i]->getValueAsVariant();
43  mProperties[i]->setValueFromVariant(item.readVariant(orgval));
44  }
45 }
46 
47 void MeshTextureData::addProperty(PropertyPtr property)
48 {
49  mProperties.push_back(property);
50  connect(property.get(), &Property::changed, this, &MeshTextureData::changed);
51 }
52 
53 void MeshTextureData::initialize()
54 {
55  mTextureImage = StringPropertySelectImage::New(mPatientModelService);
56  mTextureImage->setValueName("Texture image");
57  mTextureImage->setHelp("Select an imported 2D image to use as texture.");
58  mTextureImage->setOnly2DImagesFilter(true);
59  this->addProperty(mTextureImage);
60 
61  mTextureShape = StringProperty::initialize("texture_type", "Texture shape",
62  "The texture is applied in predefined geometric shapes. Select the shape which gives the best fit to your mesh.",
63  "Cylinder",
64  QStringList()
65  << this->getCylinderText()
66  << this->getPlaneText()
67  << this->getSphereText());
68  this->addProperty(mTextureShape);
69 
70  mScaleX = DoubleProperty::initialize("texture_scale_X", "Scale X", "How many times to draw the image along the X axis.", 1, DoubleRange(1,100000,1), 0);
71  this->addProperty(mScaleX);
72 
73  mScaleY = DoubleProperty::initialize("texture_scale_Y", "Scale Y", "How many times to draw the image along the Y axis.", 1, DoubleRange(1,100000,1), 0);
74  this->addProperty(mScaleY);
75 
76  mPositionX = DoubleProperty::initialize("texture_position_X", "Position X", "Where to start drawing the image along the X axis.", 0, DoubleRange(-100000,100000,0.01), 2);
77  this->addProperty(mPositionX);
78 
79  mPositionY = DoubleProperty::initialize("texture_position_Y", "Position Y", "Where to start drawing the image along the Y axis.", 0, DoubleRange(-100000,100000,0.01), 2);
80  this->addProperty(mPositionY);
81 
82  mRepeat = BoolProperty::initialize("repeat", "Repeat", "Repeat texture over surface", true);
83  this->addProperty(mRepeat);
84 }
85 
87 {
88  return mSphereText;
89 }
90 
92 {
93  return mPlaneText;
94 }
95 
97 {
98  return mCylinderText;
99 }
100 
102 {
103  return mPositionY;
104 }
105 
107 {
108  return mPositionX;
109 }
110 
112 {
113  return mRepeat;
114 }
115 
116 std::vector<PropertyPtr> MeshTextureData::getProperties() const
117 {
118  return mProperties;
119 }
120 
122 {
123  return mScaleY;
124 }
125 
127 {
128  return mScaleX;
129 }
130 
132 {
133  return mTextureImage;
134 }
135 
137 {
138  return mTextureShape;
139 }
140 
141 } // namespace cx
static BoolPropertyPtr initialize(const QString &uid, QString name, QString help, bool value, QDomNode root=QDomNode())
void writeVariant(const QVariant &val)
void parseXml(QDomNode &dataNode)
Utility class for describing a bounded numeric range.
Definition: cxDoubleRange.h:32
DoublePropertyPtr getPositionY() const
QString getPlaneText() const
DoublePropertyPtr getScaleX() const
StringPropertySelectImagePtr getTextureImage() const
Helper class for storing one string value in an xml document.
DoublePropertyPtr getPositionX() const
boost::shared_ptr< class StringProperty > StringPropertyPtr
QString getSphereText() const
boost::shared_ptr< class Property > PropertyPtr
BoolPropertyPtr getRepeat() const
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
boost::shared_ptr< class StringPropertySelectImage > StringPropertySelectImagePtr
void changed()
emit when the underlying data value is changed: The user interface will be updated.
static StringPropertyPtr initialize(const QString &uid, QString name, QString help, QString value, QStringList range, QDomNode root=QDomNode())
boost::shared_ptr< class DoubleProperty > DoublePropertyPtr
MeshTextureData(PatientModelServicePtr patientModelService)
std::vector< PropertyPtr > getProperties() const
DoublePropertyPtr getScaleY() const
QString getCylinderText() const
void addXml(QDomNode &dataNode)
static DoublePropertyPtr initialize(const QString &uid, QString name, QString help, double value, DoubleRange range, int decimals, QDomNode root=QDomNode())
static StringPropertySelectImagePtr New(PatientModelServicePtr patientModelService)
boost::shared_ptr< class BoolProperty > BoolPropertyPtr
StringPropertyPtr getTextureShape() const
Namespace for all CustusX production code.