22 #include <QDomDocument> 23 #include <QStringList> 24 #include <vtkColorTransferFunction.h> 25 #include <vtkPiecewiseFunction.h> 26 #include <vtkLookupTable.h> 27 #include <vtkImageData.h> 54 QDomDocument doc = dataNode.ownerDocument();
56 QDomElement alphaNode = doc.createElement(
"alpha");
59 QStringList pointStringList;
62 pointStringList.append(QString(
"%1=%2").arg(opPoint->first). arg(opPoint->second));
63 alphaNode.appendChild(doc.createTextNode(pointStringList.join(
" ")));
65 pointStringList.clear();
66 QDomElement colorNode = doc.createElement(
"color");
68 for (ColorMap::iterator colorPoint =
mColorMap.begin(); colorPoint !=
mColorMap.end(); ++colorPoint)
69 pointStringList.append(QString(
"%1=%2/%3/%4").arg(colorPoint->first). arg(colorPoint->second.red()). arg(
70 colorPoint->second.green()). arg(colorPoint->second.blue()));
71 colorNode.appendChild(doc.createTextNode(pointStringList.join(
" ")));
73 dataNode.appendChild(alphaNode);
74 dataNode.appendChild(colorNode);
76 QDomElement elem = dataNode.toElement();
81 if (dataNode.isNull())
87 QDomNode alphaNode = dataNode.namedItem(
"alpha");
89 if (!alphaNode.isNull() && !alphaNode.toElement().text().isEmpty())
91 QString alphaString = alphaNode.toElement().text();
93 QStringList alphaStringList = alphaString.split(
" ", QString::SkipEmptyParts);
94 for (
int i = 0; i < alphaStringList.size(); i++)
96 QStringList pointStringList = alphaStringList[i].split(
"=");
97 if (pointStringList.size() < 2)
99 addAlphaPoint(pointStringList[0].toInt(), pointStringList[1].toInt());
104 CX_LOG_WARNING() <<
"ImageTF3D::parseXml() found no alpha transferfunction";
107 QDomNode colorNode = dataNode.namedItem(
"color");
109 if (!colorNode.isNull() && !colorNode.toElement().text().isEmpty())
112 QStringList colorStringList = colorNode.toElement().text().split(
" ", QString::SkipEmptyParts);
113 for (
int i = 0; i < colorStringList.size(); i++)
115 QStringList pointStringList = colorStringList[i].split(
"=");
116 QStringList valueStringList = pointStringList[1].split(
"/");
117 addColorPoint(pointStringList[0].toInt(), QColor(valueStringList[0].toInt(), valueStringList[1].toInt(),
118 valueStringList[2].toInt()));
123 CX_LOG_WARNING() <<
"ImageTF3D::parseXml() found no color transferfunction";
162 double newVal = (it->first-center)*scale+center + shift;
163 int roundedVal = floor(newVal + 0.5);
164 newColorMap[roundedVal] = it->second;
174 newOpacipyMap[it->first +
shift] = it->second;
184 double old = this->
getLLR();
218 it->second += val*255;
223 double scale = val/old;
238 amax = std::max<double>(it->second, amax);
249 val = std::max(1.0, val);
254 double scale = val/old;
276 double shift = val-old;
366 tf->SetColorSpaceToRGB();
367 tf->RemoveAllPoints();
368 for (ColorMap::const_iterator iter =
mColorMap.begin(); iter !=
mColorMap.end(); ++iter)
370 QColor c = iter->second;
371 tf->AddRGBPoint(iter->first, c.redF(), c.greenF(), c.blueF());
377 tf->RemoveAllPoints();
379 tf->AddPoint(iter->first, iter->second / 255.0);
void setLLR(double val)
range [scalarMin..scalarMax]
void unsignedCT(bool onLoad)
void shiftColor(int shift, double center, double scale)
virtual void addXml(QDomNode dataNode)
adds xml information about the transferfunction and its variabels
void fillOpacityTFFromMap(vtkPiecewiseFunctionPtr tf) const
virtual void parseXml(QDomNode dataNode)
Use a XML node to load data.
vtkColorTransferFunctionPtr generateColorTF() const
void shift(int val)
shift the transfter function index values by the input amount. Used for signed/unsigned conversion...
vtkSmartPointer< class vtkPiecewiseFunction > vtkPiecewiseFunctionPtr
void resetColor(ColorMap val)
void setAlpha(double val)
range [0..1]
vtkSmartPointer< class vtkColorTransferFunction > vtkColorTransferFunctionPtr
void removeAlphaPoint(int alphaPosition)
Remove point from the opacity transfer function.
std::map< int, QColor > ColorMap
void setWindow(double val)
range [1..scalarMax-scalarMin]
void moveColorPoint(int oldpos, int newpos, QColor colorValue)
void removeColorPoint(int colorPosition)
Remove point from the color transfer function.
vtkPiecewiseFunctionPtr generateOpacityTF() const
virtual void internalsHaveChanged()
void resetAlpha(IntIntMap val)
std::map< int, int > IntIntMap
IntIntMap getOpacityMap()
Data class for Transfer Function info, either 2D or 3D.
bool similar(const CameraInfo &lhs, const CameraInfo &rhs, double tol)
void setLevel(double val)
range [scalarMin..scalarMax]
void addAlphaPoint(int alphaPosition, int alphaValue)
Add point to the opacity transfer function.
void moveAlphaPoint(int oldpos, int newpos, int alphaValue)
void shiftOpacity(int shift)
void addColorPoint(int colorPosition, QColor colorValue)
Add point to the color transfer function.
void deepCopy(ImageTFData *source)
void fillColorTFFromMap(vtkColorTransferFunctionPtr tf) const
Namespace for all CustusX production code.