@@ -38,6 +38,12 @@ using namespace SCIRun::Core::Datatypes;
3838
3939typedef SCIRun::Modules::Visualization::CreateStandardColorMap CreateStandardColorMapModule;
4040
41+ namespace
42+ {
43+ const double colormapPreviewHeight = 83 ;
44+ const double colormapPreviewWidth = 365 ;
45+ const QRectF colorMapPreviewRect (0 , 0 , colormapPreviewWidth, colormapPreviewHeight);
46+ }
4147
4248CreateStandardColorMapDialog::CreateStandardColorMapDialog (const std::string& name, ModuleStateHandle state,
4349 QWidget* parent /* = 0 */ )
@@ -94,11 +100,10 @@ void CreateStandardColorMapDialog::pullSpecial()
94100 }
95101 else
96102 {
97- previewColorMap_->addEndpoints ();
98103 for (const auto & p : pointsVec)
99104 {
100105 auto pVec = p.toVector ();
101- previewColorMap_->addPoint (QPointF (pVec[0 ].toDouble (), pVec[1 ].toDouble ()));
106+ previewColorMap_->addPoint (QPointF (pVec[0 ].toDouble () * colormapPreviewWidth, ( 1 . 0f - pVec[1 ].toDouble ()) * colormapPreviewHeight ));
102107 }
103108 }
104109}
@@ -155,18 +160,10 @@ void CreateStandardColorMapDialog::onInvertCheck(bool b)
155160AlphaFunctionManager::AlphaFunctionManager (const QPointF& start, const QPointF& end, ModuleStateHandle state, const boost::atomic<bool >& pulling) :
156161 state_(state),
157162 defaultStart_(start), defaultEnd_(end),
158- alphaFunction_(ALPHA_VECTOR_LENGTH, DEFAULT_ALPHA),
159163 dialogPulling_(pulling)
160164{
161165}
162166
163- namespace
164- {
165- const double colormapPreviewHeight = 83 ;
166- const double colormapPreviewWidth = 365 ;
167- const QRectF colorMapPreviewRect (0 , 0 , colormapPreviewWidth, colormapPreviewHeight);
168- }
169-
170167ColormapPreview::ColormapPreview (QGraphicsScene* scene, ModuleStateHandle state,
171168 const boost::atomic<bool >& pulling,
172169 QWidget* parent)
@@ -189,7 +186,6 @@ void ColormapPreview::mousePressEvent(QMouseEvent* event)
189186 }
190187
191188 // TODO: remove point if event & RightMouseButton
192-
193189 // TODO: points are movable!
194190}
195191
@@ -201,13 +197,6 @@ void ColormapPreview::addDefaultLine()
201197 alphaPath_ = scene ()->addLine (defaultStart_.x (), defaultStart_.y (),
202198 defaultEnd_.x (), defaultEnd_.y (),
203199 alphaLinePen);
204- alphaManager_.insertEndpoints ();
205- }
206-
207- void AlphaFunctionManager::insertEndpoints ()
208- {
209- alphaPoints_.insert (defaultStart_);
210- insert (defaultEnd_); // only update function and state after both endpoints are added
211200}
212201
213202void ColormapPreview::removeDefaultLine ()
@@ -218,18 +207,13 @@ void ColormapPreview::removeDefaultLine()
218207
219208void ColormapPreview::addPoint (const QPointF& point)
220209{
221- if (alphaManager_.alreadyExists (point))
222- return ;
210+ if (alphaManager_.alreadyExists (point)) return ;
223211
224212 removeDefaultLine ();
225213
226214 static QPen pointPen (Qt::white, 1 );
227215 auto item = scene ()->addEllipse (point.x () - 4 , point.y () - 4 , 8 , 8 , pointPen, QBrush (Qt::black));
228216 item->setZValue (1 );
229- // QString toolTip;
230- // QDebug tt(&toolTip);
231- // tt << "Alpha point " << point.x() << ", " << point.y() << " y% " << (1 - point.y() / sceneRect().height());
232- // item->setToolTip(toolTip);
233217 alphaManager_.insert (point);
234218
235219 drawAlphaPolyline ();
@@ -244,14 +228,12 @@ bool AlphaFunctionManager::alreadyExists(const QPointF& point) const
244228void AlphaFunctionManager::insert (const QPointF& p)
245229{
246230 alphaPoints_.insert (p);
247- updateAlphaFunction ();
248231 pushToState ();
249232}
250233
251234void AlphaFunctionManager::clear ()
252235{
253236 alphaPoints_.clear ();
254- alphaFunction_.assign (ALPHA_VECTOR_LENGTH, DEFAULT_ALPHA);
255237 pushToState ();
256238}
257239
@@ -262,19 +244,15 @@ void AlphaFunctionManager::pushToState()
262244 if (!alphaPoints_.empty ())
263245 {
264246 Variable::List alphaPointsVec;
265- // strip endpoints before saving user-added points
266247 auto begin = alphaPoints_.begin (), end = alphaPoints_.end ();
267- std::advance (begin, 1 );
268- std::advance (end, -1 );
269- std::for_each (begin, end, [&](const QPointF& p) { alphaPointsVec.emplace_back (Name (" alphaPoint" ), makeAnonymousVariableList (p.x (), p.y ())); });
248+ std::for_each (begin, end, [&](const QPointF& p) { alphaPointsVec.emplace_back (Name (" alphaPoint" ),
249+ makeAnonymousVariableList (p.x ()/colormapPreviewWidth, 1 .0f - p.y ()/colormapPreviewHeight)); });
270250 state_->setValue (Parameters::AlphaUserPointsVector, alphaPointsVec);
271251 }
272252 else
273253 {
274254 state_->setValue (Parameters::AlphaUserPointsVector, Variable::List ());
275255 }
276-
277- state_->setTransientValue (Parameters::AlphaFunctionVector, alphaFunction_);
278256 }
279257}
280258
@@ -284,15 +262,16 @@ void ColormapPreview::drawAlphaPolyline()
284262 auto pathItem = new QGraphicsPathItem ();
285263 alphaPath_ = pathItem;
286264 pathItem->setPen (alphaLinePen);
265+
287266 QPainterPath path;
288- QPointF from = defaultStart_;
289- path.moveTo (from);
267+ auto start = alphaManager_.begin ();
268+ auto end = alphaManager_.end (); std::advance (end, -1 );
269+ QPointF from = QPointF (defaultStart_.x (), start->y ());
270+ QPointF to = QPointF (defaultEnd_.x (), end->y ());
290271
291- for (const auto & point : alphaManager_)
292- {
293- path.lineTo (point);
294- path.moveTo (point);
295- }
272+ path.moveTo (from);
273+ for (const auto & point : alphaManager_) path.lineTo (point);
274+ path.lineTo (to);
296275
297276 pathItem->setPath (path);
298277 pathItem->setZValue (0 );
@@ -310,27 +289,6 @@ void ColormapPreview::clearAlphaPointGraphics()
310289 addDefaultLine ();
311290}
312291
313- void AlphaFunctionManager::updateAlphaFunction ()
314- {
315- // from v4, color endpoints (0 and 1) are fixed at alpha = 0.5.
316- // alphaFunction_ will sample from in between these endpoints, evenly spaced throughout open interval (0,1)
317-
318- for (int i = 0 ; i < static_cast <int >(alphaFunction_.size ()); ++i)
319- {
320- if (i > 0 && i < alphaFunction_.size () - 1 )
321- {
322- double color = i / static_cast <double >(ALPHA_SAMPLES + 1 );
323- auto between = alphaLineEndpointsAtColor (color);
324- alphaFunction_[i] = interpolateAlphaLineValue (between.first , between.second , color);
325- // qDebug() << "Color: " << color << "Alpha: " << alphaFunction_[i] << "between points" << between.first << between.second;
326- }
327- else
328- {
329- alphaFunction_[i] = DEFAULT_ALPHA;
330- }
331- }
332- }
333-
334292std::pair<QPointF,QPointF> AlphaFunctionManager::alphaLineEndpointsAtColor (double color) const
335293{
336294 auto rightIter = alphaPoints_.upper_bound (colorToPoint (color));
@@ -353,7 +311,7 @@ double AlphaFunctionManager::interpolateAlphaLineValue(const QPointF& leftEndpoi
353311
354312double AlphaFunctionManager::pointYToAlpha (double y) const
355313{
356- return 1 - y / colorMapPreviewRect.height ();
314+ return 1 . 0f - y / colorMapPreviewRect.height ();
357315}
358316
359317QPointF AlphaFunctionManager::colorToPoint (double color) const
0 commit comments