Starting from 2021-07-01, all LRZ GitLab users will be required to explicitly accept the GitLab Terms of Service. Please see the detailed information at https://doku.lrz.de/display/PUBLIC/GitLab and make sure that your projects conform to the requirements.

Commit 22aa4562 authored by Hossain Mahmud's avatar Hossain Mahmud
Browse files

Fixes: saving color for simpletransferfunc, geometry1d..:addKeyPoint() added,...

Fixes: saving color for simpletransferfunc, geometry1d..:addKeyPoint() added, ..editor::mousePressEvent updated, transfer..lua update to save all point and colors
parent 29d78b68
......@@ -189,19 +189,27 @@ namespace campvis {
{
tbb::mutex::scoped_lock lock(_localMutex);
float pos = static_cast<float>(e->x()) / static_cast<float>(_canvas->width());
cgt::col4 col = cgt::col4(255);
// add a control point on CTRL+Click
std::vector<TFGeometry1D::KeyPoint>& kpts = g->getKeyPoints();
TFGeometry1D::KeyPoint kp(static_cast<float>(e->x()) / static_cast<float>(_canvas->width()), cgt::col4(255));
std::vector<TFGeometry1D::KeyPoint>::iterator lb = std::upper_bound(kpts.begin(), kpts.end(), kp);
if (lb != kpts.end()) {
kp._color = lb->_color;
}
else {
kp._color = kpts.back()._color;
}
//std::vector<TFGeometry1D::KeyPoint>& kpts = g->getKeyPoints();
//TFGeometry1D::KeyPoint kp(static_cast<float>(e->x()) / static_cast<float>(_canvas->width()), cgt::col4(255));
//std::vector<TFGeometry1D::KeyPoint>::iterator lb = std::upper_bound(kpts.begin(), kpts.end(), kp);
//if (lb != kpts.end()) {
// kp._color = lb->_color;
// col = lb->_color;
//}
//else {
// kp._color = kpts.back()._color;
// col = kpts.back()._color;
//}
float alpha = cgt::clamp(static_cast<float>(_canvas->height() - e->y()) / static_cast<float>(_canvas->height()), 0.f, 1.f);
kp._color.a = static_cast<uint8_t>(alpha * 255.f);
kpts.insert(lb, kp);
//kp._color.a = static_cast<uint8_t>(alpha * 255.f);
col.a = static_cast<uint8_t>(alpha * 255.f);
//kpts.insert(lb, kp);
g->addKeyPoint(pos, alpha);
//g->addKeyPoint(pos, col);
}
updateManipulators();
......
......@@ -193,6 +193,9 @@ namespace campvis {
public:
virtual ~TFGeometry1D();
static TFGeometry1D* createQuad(const cgt::vec2& interval, const cgt::col4& leftColor, const cgt::col4& rightColor);
void addKeyPoint(float position, float alpha);
void addKeyPoint(float position, const cgt::col4& color);
};
/* TFGeometry2D */
......@@ -221,6 +224,8 @@ namespace campvis {
SimpleTransferFunction(size_t size, const cgt::vec2& intensityDomain = cgt::vec2(0.f, 1.f));
virtual ~SimpleTransferFunction();
virtual SimpleTransferFunction* clone() const;
void setLeftColor(const cgt::col4& color);
void setRightColor(const cgt::col4& color);
};
......
......@@ -137,4 +137,24 @@ namespace campvis {
return new TFGeometry1D(keyPoints);
}
void TFGeometry1D::addKeyPoint( float position, float alpha) {
TFGeometry1D::KeyPoint kp(position, cgt::col4(255));
std::vector<TFGeometry1D::KeyPoint>::iterator lb = std::upper_bound(_keyPoints.begin(), _keyPoints.end(), kp);
if (lb != _keyPoints.end()) {
kp._color = lb->_color;
}
else {
kp._color = _keyPoints.back()._color;
}
kp._color.a = static_cast<uint8_t>(alpha * 255.f);
_keyPoints.insert(lb, kp);
}
void TFGeometry1D::addKeyPoint( float position, const cgt::col4& color ) {
TFGeometry1D::KeyPoint kp(position, cgt::col4(255));
std::vector<TFGeometry1D::KeyPoint>::iterator lb = std::upper_bound(_keyPoints.begin(), _keyPoints.end(), kp);
kp._color = color; // Check implementation of upper_bound to set this in constructor
_keyPoints.insert(lb, kp);
}
}
\ No newline at end of file
......@@ -95,6 +95,20 @@ namespace campvis {
/// Signal to be emitted when this TF geometry has changed.
sigslot::signal0 s_changed;
/**
* Adds a new KeyPoint
* \param position Position of new KeyPoint
* \param color Alpha of color of new KeyPoint. Color is interpolated from neighbors
*/
void addKeyPoint(float position, float alpha);
/**
* Adds a new KeyPoint
* \param position Position of new KeyPoint
* \param alpha Color for left KeyPoint
*/
void addKeyPoint(float position, const cgt::col4& color);
/**
* Creates a simple quad geometry for the given interval.
......
......@@ -53,19 +53,29 @@ namespace campvis {
if (SimpleTransferFunction* tester = dynamic_cast<SimpleTransferFunction*>(tf)) {
// dvrTF = ...
ret += "tf = campvis.SimpleTransferFunction(" + StringUtils::toString(tf->getSize().x)
+", cgt.vec2("+StringUtils::toString(domain.x) +", " + StringUtils::toString(domain.y) + "))\n";
ret += "tf = campvis.SimpleTransferFunction(" + StringUtils::toString((float)tf->getSize().x)
+", cgt.vec2("+StringUtils::toString((float)domain.x) +", " + StringUtils::toString((float)domain.y) + "))\n";
ret += "tf:setLeftColor(cgt.col4(" + StringUtils::toString((float)tester->getLeftColor().r)
+ ", " + StringUtils::toString((float)tester->getLeftColor().g)
+ ", " + StringUtils::toString((float)tester->getLeftColor().b)
+ ", " + StringUtils::toString((float)tester->getLeftColor().a) + "))\n";
ret += "tf:setRightColor(cgt.col4(" + StringUtils::toString((float)tester->getRightColor().r)
+ ", " + StringUtils::toString((float)tester->getRightColor().g)
+ ", " + StringUtils::toString((float)tester->getRightColor().b)
+ ", " + StringUtils::toString((float)tester->getRightColor().a) + "))\n";
}
if (Geometry1DTransferFunction* tester = dynamic_cast<Geometry1DTransferFunction*>(tf)) {
// dvrTF = ...
ret += "tf = campvis.Geometry1DTransferFunction(" + StringUtils::toString(tf->getSize().x)
+", cgt.vec2("+StringUtils::toString(domain.x) +", " + StringUtils::toString(domain.y) + "))\n";
ret += "tf = campvis.Geometry1DTransferFunction(" + StringUtils::toString((float)tf->getSize().x)
+", cgt.vec2("+StringUtils::toString((float)domain.x) +", " + StringUtils::toString((float)domain.y) + "))\n";
const std::vector<TFGeometry1D*>& _geometries = tester->getGeometries();
for (int i = 0; i < _geometries.size(); i++) {
std::vector<TFGeometry1D::KeyPoint>& kp = _geometries[i]->getKeyPoints();
//cgtAssert(kp.size() < 2, "There should be at least two key points");
cgtAssert(kp.size() >= 2, "There should be at least two key points");
float x = kp[0]._position;
float y = kp[1]._position;
cgt::col4 lc = kp[0]._color;
......@@ -84,25 +94,34 @@ namespace campvis {
+ StringUtils::toString((float)rc.g) + ", "
+ StringUtils::toString((float)rc.b) + ", "
+ StringUtils::toString((float)rc.a) + "))\n";
for (int i = 2; i < kp.size(); i++) {
ret += "geometry:addKeyPoint(" + StringUtils::toString(kp[i]._position)
+ ", cgt.col4(" + StringUtils::toString((float)kp[i]._color.r) + ", "
+ StringUtils::toString((float)kp[i]._color.g) + ", "
+ StringUtils::toString((float)kp[i]._color.b) + ", "
+ StringUtils::toString((float)kp[i]._color.a) + "))\n";
}
// dvrTF.addGeo ...
ret += "tf:addGeometry(geometry)\n";
}
}
if (Geometry2DTransferFunction* tester = dynamic_cast<Geometry2DTransferFunction*>(tf)) {
// dvrTF = ...
//TODO: fix me when 2D geometry is fully implemented
//FIXME: things to do
cgtAssert(1 != 1, "Fix Geometry2DTransferFunction lua scripting first");
ret += "tf = campvis.Geometry2DTransferFunction(" + StringUtils::toString(tf->getSize().x)
+", cgt.vec2("+StringUtils::toString(domain.x) +", " + StringUtils::toString(domain.y) + "))\n";
const std::vector<TFGeometry2D*>& _geometries = tester->getGeometries();
for (int i = 0; i < _geometries.size(); i++) {
std::vector<TFGeometry2D::KeyPoint>& kp = _geometries[i]->getKeyPoints();
//cgtAssert(kp.size() < 4, "There should be at least two key points");
cgtAssert(kp.size() >= 4, "There should be at least four key points");
cgt::vec2 ll = kp[0]._position;
cgt::vec2 ur = kp[2]._position;
cgt::col4 col = kp[0]._color;
// geometry = ...
ret += "geometry = campvis.TFGeometry1D_createQuad(cgt.vec2("+ StringUtils::toString(ll.x)
+ "," + StringUtils::toString(ll.y) + "), "
......@@ -113,7 +132,6 @@ namespace campvis {
+ StringUtils::toString((float)col.g) + ", "
+ StringUtils::toString((float)col.b) + ", "
+ StringUtils::toString((float)col.a) + "))\n";
// dvrTF.addGeo ...
ret += "tf:addGeometry(geometry)\n";
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment