Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/7429_splatterplot_4D_data'
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Oct 11, 2013
2 parents f89701a + c62ac54 commit 2c6f14e
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkUnstructuredGridAlgorithm.h"
#include "vtkUnstructuredGrid.h"

Expand Down Expand Up @@ -75,6 +76,14 @@ void vtkSplatterPlot::SetTopPercentile(double topPercentile)
}
}

/**
* Getter for the time
* @return the time.
*/
double vtkSplatterPlot::getTime() const
{
return m_time;
}

int vtkSplatterPlot::RequestData(vtkInformation *,
vtkInformationVector **inputVector,
Expand All @@ -87,6 +96,13 @@ int vtkSplatterPlot::RequestData(vtkInformation *,
vtkDataSet *output = vtkDataSet::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));

if (outInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP()))
{
// usually only one actual step requested
m_time = outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP());
}
m_presenter->setTime(m_time);

vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
vtkDataSet *input = vtkDataSet::SafeDownCast(
inInfo->Get(vtkDataObject::DATA_OBJECT()));
Expand Down Expand Up @@ -145,12 +161,10 @@ void vtkSplatterPlot::PrintSelf(ostream& os, vtkIndent indent)
/**
* Output the progress information and progress text.
* @param : progress
*@param : message
* @param : message
*/
void vtkSplatterPlot::updateAlgorithmProgress(double progress, const std::string& message)
{
this->SetProgress(progress);
this->SetProgressText(message.c_str());
}


Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class VTK_EXPORT vtkSplatterPlot : public vtkUnstructuredGridAlgorithm
public:
static vtkSplatterPlot *New();
vtkTypeMacro(vtkSplatterPlot, vtkUnstructuredGridAlgorithm);
double getTime() const;
void PrintSelf(ostream& os, vtkIndent indent);
void SetNumberOfPoints(int nPoints);
void SetTopPercentile(double topPercentile);
Expand All @@ -38,9 +39,10 @@ class VTK_EXPORT vtkSplatterPlot : public vtkUnstructuredGridAlgorithm
Mantid::VATES::vtkSplatterPlotFactory *m_presenter;
/// Holder for the workspace name
std::string m_wsName;
/// Time.
double m_time;

vtkSplatterPlot(const vtkSplatterPlot&);
void operator = (const vtkSplatterPlot&);

};
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ class DLLExport vtkSplatterPlotFactory : public vtkDataSetFactory
/// Set percentage of boxes from which points will be plotted
virtual void SetPercentToUse(double percentToUse);

/// Set the time value.
void setTime(double timeStep);

private:

template<typename MDE, size_t nd>
Expand Down Expand Up @@ -117,7 +120,8 @@ class DLLExport vtkSplatterPlotFactory : public vtkDataSetFactory
/// Variable to hold sorted list, so sort doesn't have to be repeated
mutable std::vector< Mantid::API::IMDNode * > m_sortedBoxes;


/// Time value.
double m_time;
};

}
Expand Down
23 changes: 16 additions & 7 deletions Code/Mantid/Vates/VatesAPI/src/vtkSplatterPlotFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ namespace VATES
// boxes to use.
size_t totalPoints = ws->getNPoints();
size_t numPoints = m_numPoints;

if (numPoints > totalPoints)
{
numPoints = totalPoints;
Expand Down Expand Up @@ -144,7 +145,6 @@ namespace VATES
std::cout << "DONE SORTING" << std::endl;
}
}

size_t num_boxes_to_use = static_cast<size_t>(percent_to_use * static_cast<double>(m_sortedBoxes.size()) / 100.0);
if (num_boxes_to_use >= m_sortedBoxes.size())
{
Expand Down Expand Up @@ -329,6 +329,7 @@ namespace VATES
// Define where the slice is in 4D
// TODO: Where to slice? Right now is just 0
std::vector<coord_t> point(nd, 0);
point[3] = coord_t(m_time); //Specifically for 4th/time dimension.

// Define two opposing planes that point in all higher dimensions
std::vector<coord_t> normal1(nd, 0);
Expand All @@ -354,7 +355,7 @@ namespace VATES
// Clean up
if (this->slice)
{
delete this->sliceMask;
delete[] this->sliceMask;
delete this->sliceImplicitFunction;
}

Expand Down Expand Up @@ -388,11 +389,6 @@ namespace VATES
{
throw std::runtime_error("Invalid vtkSplatterPlotFactory. Workspace must have at least 3 dimensions.");
}
size_t nd = m_workspace->getNonIntegratedDimensions().size();
if (nd > 3)
{
throw std::runtime_error("SplatterPlot cannot handle 4D data, please integrate to 3D!");
}
}

/**
Expand Down Expand Up @@ -429,5 +425,18 @@ namespace VATES
}
}

/**
* Set the time value.
* @param double : the time
*/
void vtkSplatterPlotFactory::setTime(double time)
{
if (m_time != time)
{
m_buildSortedList = true;
}
m_time = time;
}

}
}
25 changes: 6 additions & 19 deletions Code/Mantid/Vates/VatesAPI/test/vtkSplatterPlotFactoryTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,37 +91,24 @@ class vtkSplatterPlotFactoryTest : public CxxTest::TestSuite

Mantid::MDEvents::MDEventWorkspace4Lean::sptr ws = MDEventsTestHelper::makeMDEW<4>(5, -10.0, 10.0, 1);
vtkSplatterPlotFactory factory(ThresholdRange_scptr(new UserDefinedThresholdRange(0, 1)), "signal");
TS_ASSERT_THROWS(factory.initialize(ws), std::runtime_error&);
//vtkDataSet* product = NULL;
factory.initialize(ws);
vtkDataSet* product = NULL;

//TS_ASSERT_THROWS(factory.create(progressUpdate), std::runtime_error&);
//TS_ASSERT_THROWS_NOTHING(product = factory.create(progressUpdate));
TS_ASSERT_THROWS_NOTHING(product = factory.create(progressUpdate));

/*
const size_t expected_n_points = 8*125;
const size_t expected_n_cells = 125;
// 6 is 5% of 125
const size_t expected_n_points = 6;
const size_t expected_n_cells = 6;
const size_t expected_n_signals = expected_n_cells;

TSM_ASSERT_EQUALS("Wrong number of points", expected_n_points, product->GetNumberOfPoints());
TSM_ASSERT_EQUALS("Wrong number of cells", expected_n_cells, product->GetNumberOfCells());
TSM_ASSERT_EQUALS("Wrong number of points to cells. Hexahedron has 8 vertexes.", expected_n_cells * 8, product->GetNumberOfPoints());
TSM_ASSERT_EQUALS("No signal Array", "signal", std::string(product->GetCellData()->GetArray(0)->GetName()));
TSM_ASSERT_EQUALS("Wrong sized signal Array", expected_n_signals, product->GetCellData()->GetArray(0)->GetSize());

//Check dataset bounds
double* bounds = product->GetBounds();
TS_ASSERT_EQUALS(-9.5, bounds[0]);
TS_ASSERT_EQUALS(9.5, bounds[1]);
TS_ASSERT_EQUALS(-9.5, bounds[2]);
TS_ASSERT_EQUALS(9.5, bounds[3]);
TS_ASSERT_EQUALS(-9.5, bounds[4]);
TS_ASSERT_EQUALS(9.5, bounds[5]);
product->Delete();
*/
}


};

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,6 @@ void SplatterPlotView::render()
QString renderType = "Points";
pqObjectBuilder* builder = pqApplicationCore::instance()->getObjectBuilder();

if (this->checkForBadDimensions(src))
{
return;
}

// Do not allow overplotting of MDWorkspaces
if (!this->isPeaksWorkspace(src) && NULL != this->splatSource)
{
Expand Down Expand Up @@ -208,41 +203,6 @@ void SplatterPlotView::resetDisplay()
this->view->resetDisplay();
}

/**
* This function checks any incoming MDEventWorkspace to ensure that it has
* only 3 non-integrated dimensions. Have to do this since the
* vtkSplatterPlotFactory isn't setup properly.
*
* @param src : The pipeline source to perform the dimension check
* @return True if there are more than 3 non-integrated dimensions
*/
bool SplatterPlotView::checkForBadDimensions(pqPipelineSource *src)
{
if (!this->isPeaksWorkspace(src))
{
QString wsName(vtkSMPropertyHelper(src->getProxy(),
"Mantid Workspace Name", true).GetAsString());
if(!wsName.isEmpty())
{
ADSWorkspaceProvider<Mantid::API::IMDEventWorkspace> wsProvider;
API::Workspace_sptr ws = wsProvider.fetchWorkspace(wsName.toStdString());
API::IMDEventWorkspace_const_sptr infoWs = boost::dynamic_pointer_cast<const API::IMDEventWorkspace>(ws);
std::size_t numDims = infoWs->getNonIntegratedDimensions().size();
if (numDims > 3)
{
QMessageBox::warning(this, QApplication::tr("Dimension Warning"),
QApplication::tr("SplatterPlot mode does not allow "\
"4D data. Please integrate to 3D "\
"via SliceMD!. Returning to Standard View."));
pqActiveObjects::instance().setActiveSource(src);
emit this->resetToStandardView();
return true;
}
}
}
return false;
}

/**
* This function checks to see if the Override PC button has been
* toggled. If the state is unchecked (false), we want to make sure
Expand Down

0 comments on commit 2c6f14e

Please sign in to comment.