@@ -25,11 +25,15 @@ ImageSettingsAction::ImageSettingsAction(QObject* parent, const QString& title)
2525 _interpolationTypeAction(this , " Interpolate" , interpolationTypes.values(), "Bilinear"),
2626 _useConstantColorAction(this , " Use constant color" , false ),
2727 _fixChannelRangesToColorSpaceAction(this , " Set channel ranges to color space" , false ),
28- _constantColorAction(this , " Constant color" , QColor(Qt::white))
28+ _constantColorAction(this , " Constant color" , QColor(Qt::white)),
29+ _useBackgroundAction(this , " Background" ),
30+ _backgroundDimAction(this , " Background Dimension" )
2931{
3032 addAction (&_opacityAction);
3133 addAction (&_subsampleFactorAction);
3234 addAction (&_colorSpaceAction);
35+ addAction (&_useBackgroundAction);
36+ addAction (&_backgroundDimAction);
3337 addAction (&_scalarChannel1Action);
3438 addAction (&_scalarChannel2Action);
3539 addAction (&_scalarChannel3Action);
@@ -42,6 +46,9 @@ ImageSettingsAction::ImageSettingsAction(QObject* parent, const QString& title)
4246
4347 _subsampleFactorAction.setVisible (false );
4448
49+ _useBackgroundAction.setVisible (false );
50+ _backgroundDimAction.setVisible (false );
51+
4552 _opacityAction.setToolTip (" Image layer opacity" );
4653 _subsampleFactorAction.setToolTip (" Subsampling factor" );
4754 _scalarChannel1Action.setToolTip (" Scalar channel 1" );
@@ -188,6 +195,26 @@ void ImageSettingsAction::initialize(Layer* layer)
188195 _scalarChannel1Action.getWindowLevelAction ().setEnabled (false );
189196 _scalarChannel2Action.getWindowLevelAction ().setEnabled (false );
190197 _scalarChannel3Action.getWindowLevelAction ().setEnabled (false );
198+
199+ _useBackgroundAction.setVisible (true );
200+ _useBackgroundAction.setChecked (false );
201+ _backgroundDimAction.setVisible (true );
202+ _backgroundDimAction.setEnabled (false );
203+ connect (&_useBackgroundAction, &ToggleAction::toggled, this , [this ]() { _backgroundDimAction.setEnabled (_useBackgroundAction.isChecked ()); });
204+ // get parent point dataset's dimensions
205+ auto parent = Dataset<Clusters>(_layer->getSourceDataset ());
206+ while (parent->getDataType () != PointType) {
207+ parent = parent->getParent ();
208+ }
209+ Dataset<Points> points = parent;
210+ if (points.isValid ()) {
211+ QStringList parentDimNames;
212+ for (auto name: points->getDimensionNames ()) parentDimNames << name;
213+
214+ _backgroundDimAction.setOptions (parentDimNames);
215+ _backgroundDimAction.setCurrentIndex (0 );
216+ }
217+
191218 }
192219 else {
193220 if (_layer->getNumberOfImages () >= 2 ) {
@@ -199,6 +226,9 @@ void ImageSettingsAction::initialize(Layer* layer)
199226 }
200227 }
201228
229+ connect (&_backgroundDimAction, &OptionAction::currentIndexChanged, this , &ImageSettingsAction::updateColorMapImage);
230+ connect (&_useBackgroundAction, &ToggleAction::toggled, this , &ImageSettingsAction::updateColorMapImage);
231+
202232 connect (&_colorMap1DAction, &ColorMapAction::imageChanged, this , &ImageSettingsAction::updateColorMapImage);
203233 connect (&_colorMap2DAction, &ColorMapAction::imageChanged, this , &ImageSettingsAction::updateColorMapImage);
204234 // connect(&_colorMapAction.getDiscretizeAction(), &ToggleAction::toggled, this, &ImageSettingsAction::updateColorMapImage);
@@ -274,11 +304,47 @@ const std::uint32_t ImageSettingsAction::getNumberOfActiveScalarChannels() const
274304 return 0 ;
275305}
276306
277- QImage ImageSettingsAction::getColorMapImage () const
307+ QImage ImageSettingsAction::getColorMapImage ()
278308{
279309 if (_layer->getSourceDataset ()->getDataType () == ClusterType) {
280310 const auto & clusters = Dataset<Clusters>(_layer->getSourceDataset ())->getClusters ();
281311
312+ // get parent point dataset's dimensions
313+ auto parent = Dataset<Clusters>(_layer->getSourceDataset ());
314+ while (parent->getDataType () != PointType) {
315+ parent = parent->getParent ();
316+ }
317+ Dataset<Points> points = parent;
318+ _backgroundMin = 0.0 ;
319+ _backgroundMax = 0.0 ;
320+ if (points.isValid () && _useBackgroundAction.isChecked ()) {
321+ float min = std::numeric_limits<float >::max ();
322+ float max = std::numeric_limits<float >::min ();
323+ int dim = _backgroundDimAction.getCurrentIndex ();
324+ for (const auto & cluster: clusters) {
325+ if (dim < 0 ) break ;
326+ int numIndices = cluster.getNumberOfIndices ();
327+ std::vector<float > data (numIndices);
328+ points->populateDataForDimensions (data, std::vector<int >{dim}, cluster.getIndices ());
329+ min = std::min (*std::min_element (data.begin (), data.end ()), min);
330+ max = std::max (*std::max_element (data.begin (), data.end ()), max);
331+ }
332+ _backgroundMin = min;
333+ _backgroundMax = max;
334+
335+ if (dim >= 0 ) {
336+ int numPixels = _layer->getImagesDataset ()->getNumberOfPixels ();
337+ std::vector<float > fullImage (numPixels);
338+ points->extractDataForDimension (fullImage, dim);
339+
340+ _scalarData.clear ();
341+ _scalarData.reserve (numPixels);
342+ std::copy (fullImage.begin (), fullImage.end (), std::back_inserter (_scalarData));
343+ }
344+ }
345+ _scalarDataRange.first = _backgroundMin;
346+ _scalarDataRange.second = _backgroundMax;
347+
282348 QImage discreteColorMapImage (static_cast <std::int32_t >(clusters.size ()), 1 , QImage::Format::Format_RGB32);
283349
284350 auto clusterIndex = 0 ;
@@ -323,8 +389,12 @@ void ImageSettingsAction::updateColorMapImage()
323389 }
324390
325391
326- if (_colorSpaceAction.getCurrentIndex () <= 1 )
392+ if (_colorSpaceAction.getCurrentIndex () <= 1 ) {
327393 _layer->setColorMapImage (getColorMapImage (), interpolationType);
394+ if (_layer->getSourceDataset ()->getDataType () == ClusterType && _scalarData.size () > 0 ) {
395+ _layer->setChannelScalarData (ScalarChannelAction::Identifier::Channel2, _scalarData, _scalarDataRange);
396+ }
397+ }
328398}
329399
330400void ImageSettingsAction::colorSpaceChanged ()
0 commit comments