Commit 9365c184 authored by Brad Whitlock's avatar Brad Whitlock
Browse files

Enhanced libsim adaptor to be able to do multiple pipelines.

parent 03adb284
......@@ -31,7 +31,9 @@ endif()
if(ENABLE_LIBSIM)
list(APPEND sources
libsim/AnalysisAdaptor.cxx
libsim/AnalysisAdaptor.h)
libsim/AnalysisAdaptor.h
libsim/ImageProperties.cxx
libsim/ImageProperties.h)
endif()
#-----------------------------------------------------------------------
......
......@@ -17,6 +17,7 @@
#endif
#ifdef ENABLE_LIBSIM
# include "libsim/AnalysisAdaptor.h"
# include "libsim/ImageProperties.h"
#endif
#include <vector>
......@@ -215,7 +216,57 @@ public:
else
cout << "NOT creating Libsim Analysis Adaptor" << endl;
// Add slice stuff ...
libsim::ImageProperties imageProps;
if(node.attribute("image-filename") != NULL)
imageProps.SetFilename(node.attribute("image-filename").value());
if(node.attribute("image-width") != NULL)
imageProps.SetWidth(node.attribute("image-width").as_int());
if(node.attribute("image-height") != NULL)
imageProps.SetHeight(node.attribute("image-height").as_int());
if(node.attribute("image-height") != NULL)
imageProps.SetHeight(node.attribute("image-height").as_int());
std::string plots, plotVars;
double origin[3] = {0.,0.,0.};
double normal[3] = {1.,0.,0.};
bool slice = false, project = false;
if(node.attribute("plots") != NULL)
plots = node.attribute("plots").value();
if(node.attribute("plotvars") != NULL)
plotVars = node.attribute("plotvars").value();
if(node.attribute("slice-origin") != NULL)
{
double tmp[3];
if(sscanf(node.attribute("slice-origin").value(),
"%lg,%lg,%lg", &tmp[0], &tmp[1], &tmp[2]) == 3)
{
slice = true;
origin[0] = tmp[0];
origin[1] = tmp[1];
origin[2] = tmp[2];
}
}
if(node.attribute("slice-normal") != NULL)
{
double tmp[3];
if(sscanf(node.attribute("slice-normal").value(),
"%lg,%lg,%lg", &tmp[0], &tmp[1], &tmp[2]) == 3)
{
slice = true;
normal[0] = tmp[0];
normal[1] = tmp[1];
normal[2] = tmp[2];
}
}
if(node.attribute("slice-project") != NULL)
project = node.attribute("slice-project").as_int() != 0;
// Add the image that we want to make.
if(!this->LibsimAnalysisAdaptor->AddPlots(plots, plotVars,
slice, project, origin, normal, imageProps))
{
return -2;
}
return 0;
}
......
#include "AnalysisAdaptor.h"
#include "ImageProperties.h"
#include <sensei/DataAdaptor.h>
#include <timer/Timer.h>
......@@ -30,6 +31,40 @@ namespace libsim
///////////////////////////////////////////////////////////////////////////////
class PlotRecord
{
public:
PlotRecord() : imageProps(), plots(), plotVars(), slice(false), project2d(false)
{
origin[0] = origin[1] = origin[2] = 0.;
normal[0] = 1.; normal[1] = normal[2] = 0.;
}
~PlotRecord()
{
}
static std::vector<std::string> SplitAtCommas(const std::string &s)
{
std::stringstream ss(s);
std::vector<std::string> result;
while(ss.good())
{
std::string substr;
getline(ss, substr, ',' );
result.push_back(substr);
}
return result;
}
ImageProperties imageProps;
std::vector<std::string> plots;
std::vector<std::string> plotVars;
bool slice;
bool project2d;
double origin[3];
double normal[3];
};
class AnalysisAdaptor::PrivateData
{
public:
......@@ -44,6 +79,12 @@ public:
void PrintSelf(ostream& os, vtkIndent indent);
bool Initialize();
bool Execute(DataAdaptor *dataAdaptor);
bool AddPlots(const std::string &plots,
const std::string &plotVars,
bool slice, bool project2d,
const double origin[3], const double normal[3],
const ImageProperties &imgProps);
private:
static int broadcast_int(int *value, int sender, void *cbdata);
static int broadcast_string(char *str, int len, int sender, void *cbdata);
......@@ -63,6 +104,7 @@ private:
int *doms_per_rank;
std::vector<vtkDataSet *> domains;
std::string traceFile, options, visitdir;
std::vector<PlotRecord> plots;
MPI_Comm comm;
static bool runtimeLoaded;
static int instances;
......@@ -139,6 +181,28 @@ AnalysisAdaptor::PrivateData::PrintSelf(ostream &os, vtkIndent indent)
}
}
bool
AnalysisAdaptor::PrivateData::AddPlots(const std::string &plts,
const std::string &plotVars,
bool slice, bool project2d,
const double origin[3], const double normal[3],
const ImageProperties &imgProps)
{
PlotRecord p;
p.imageProps = imgProps;
p.plots = PlotRecord::SplitAtCommas(plts);
p.plotVars = PlotRecord::SplitAtCommas(plotVars);
p.slice = slice;
p.project2d = project2d;
memcpy(p.origin, origin, 3 * sizeof(double));
memcpy(p.normal, normal, 3 * sizeof(double));
bool retval = !p.plots.empty() && (p.plots.size() == p.plotVars.size());
if(retval)
plots.push_back(p);
return retval;
}
bool
AnalysisAdaptor::PrivateData::Initialize()
{
......@@ -252,16 +316,68 @@ AnalysisAdaptor::PrivateData::Execute(DataAdaptor *dataAdaptor)
VisItTimeStepChanged();
// Now that the runtime stuff is loaded, we can execute some plots.
if(VisItAddPlot("Pseudocolor", "temperature") == VISIT_OKAY)
for(size_t i = 0; i < plots.size(); ++i)
{
// Add all the plots in this group.
int *ap = new int[plots[i].plots.size()];
int np = 0;
for(size_t j = 0; j < plots[i].plots.size(); ++j)
{
if(VisItAddPlot(plots[i].plots[j].c_str(),plots[i].plotVars[j].c_str()) == VISIT_OKAY)
{
// Use a better color table.
const char *ctName = "hot_desaturated";
if(plots[i].plots[j] == "Pseudocolor")
VisItSetPlotOptionsS("colorTableName", ctName);
else if(plots[i].plots[j] == "Vector")
{
VisItSetPlotOptionsS("colorTableName", ctName);
VisItSetPlotOptionsB("colorByMag", true);
}
ap[np] = np++;
}
else if(rank == 0)
printf("ERROR: VisItAddPlot failed.\n");
}
// Select all plots.
VisItSetActivePlots(ap, np);
delete [] ap;
// Add a slice operator to all plots.
if(plots[i].slice)
{
VisItAddOperator("Slice", 1);
VisItSetOperatorOptionsI("originType", 0); // point intercept
VisItSetOperatorOptionsDv("originPoint", plots[i].origin, 3);
VisItSetOperatorOptionsDv("normal", plots[i].normal, 3);
VisItSetOperatorOptionsB("project2d", plots[i].project2d ? 1 : 0);
}
if(VisItDrawPlots() == VISIT_OKAY)
{
int w = 1920/2, h = 1080/2;
// Get the image properties.
int w = plots[i].imageProps.GetWidth();
int h = plots[i].imageProps.GetHeight();
std::string filename;
filename = MakeFileName("libsim%ts.png",
filename = MakeFileName(plots[i].imageProps.GetFilename(),
dataAdaptor->GetDataTimeStep(),
dataAdaptor->GetDataTime());
if(VisItSaveWindow(filename.c_str(), w, h, VISIT_IMAGEFORMAT_PNG) == VISIT_OKAY)
int format = VISIT_IMAGEFORMAT_PNG;
if(plots[i].imageProps.GetFormat() == "bmp")
format = VISIT_IMAGEFORMAT_BMP;
else if(plots[i].imageProps.GetFormat() == "jpeg")
format = VISIT_IMAGEFORMAT_JPEG;
else if(plots[i].imageProps.GetFormat() == "png")
format = VISIT_IMAGEFORMAT_PNG;
else if(plots[i].imageProps.GetFormat() == "ppm")
format = VISIT_IMAGEFORMAT_PPM;
else if(plots[i].imageProps.GetFormat() == "tiff")
format = VISIT_IMAGEFORMAT_TIFF;
// Save an image.
if(VisItSaveWindow(filename.c_str(), w, h, format) == VISIT_OKAY)
{
retval = true;
}
......@@ -271,10 +387,9 @@ AnalysisAdaptor::PrivateData::Execute(DataAdaptor *dataAdaptor)
else if(rank == 0)
printf("ERROR: VisItDrawPlots failed.\n");
// Delete the plots.
VisItDeleteActivePlots();
}
else if(rank == 0)
printf("ERROR: VisItAddPlot failed.\n");
#endif
return retval;
......@@ -426,7 +541,7 @@ AnalysisAdaptor::PrivateData::GetMetaData(void *cbdata)
/* Set the simulation state. */
VisIt_SimulationMetaData_setMode(md, VISIT_SIMMODE_RUNNING);
VisIt_SimulationMetaData_setCycleTime(md, da->GetDataTime(), da->GetDataTimeStep());
VisIt_SimulationMetaData_setCycleTime(md, da->GetDataTimeStep(), da->GetDataTime());
/* Add mesh metadata. */
if(VisIt_MeshMetaData_alloc(&mmd) == VISIT_OKAY)
......@@ -738,6 +853,17 @@ AnalysisAdaptor::SetComm(MPI_Comm c)
d->SetComm(c);
}
//-----------------------------------------------------------------------------
bool
AnalysisAdaptor::AddPlots(const std::string &plots,
const std::string &plotVars,
bool slice, bool project2d,
const double origin[3], const double normal[3],
const ImageProperties &imgProps)
{
return d->AddPlots(plots, plotVars, slice, project2d, origin, normal, imgProps);
}
//-----------------------------------------------------------------------------
void
AnalysisAdaptor::Initialize()
......
......@@ -11,6 +11,8 @@ namespace libsim
{
using sensei::DataAdaptor;
class ImageProperties;
/// @brief Analysis adaptor for libsim-based analysis pipelines.
///
/// AnalysisAdaptor is a subclass of AnalysisAdaptor that is
......@@ -33,8 +35,13 @@ public:
virtual bool Execute(DataAdaptor* data);
// NOTE: we might need to provide a method to accept some kind of pipeline description.
// Simple method to add some VisIt plots. The limit is how complex
// we want to make this.
bool AddPlots(const std::string &plots,
const std::string &plotVars,
bool slice, bool project2d,
const double origin[3], const double normal[3],
const ImageProperties &imgProps);
//BTX
protected:
AnalysisAdaptor();
......
#include "ImageProperties.h"
namespace sensei
{
namespace libsim
{
ImageProperties::ImageProperties() : filename("image%ts.png"),
format("png"), width(1920), height(1080)
{
}
ImageProperties::~ImageProperties()
{
}
void ImageProperties::SetFilename(const std::string &s)
{
filename = s;
}
void ImageProperties::SetWidth(int val)
{
if(val > 0) width = val;
}
void ImageProperties::SetHeight(int val)
{
if(val > 0) height = val;
}
void ImageProperties::SetFormat(const std::string &s)
{
if(s == "bmp" || s == "BMP")
format = "bmp";
else if(s == "jpeg" || s == "jpg" || s == "JPEG" || s == "JPG")
format = "jpeg";
else if(s == "png" || s == "PNG")
format = "png";
else if(s == "ppm" || s == "PPM")
format = "ppm";
else if(s == "rgb" || s == "RGB")
format = "rgb";
else if(s == "tif" || s == "TIF" || s == "tiff" || s == "TIFF")
format = "tiff";
}
const std::string &ImageProperties::GetFilename() const
{ return filename; }
const std::string &ImageProperties::GetFormat() const
{ return format; }
int ImageProperties::GetWidth() const
{ return width; }
int ImageProperties::GetHeight() const
{ return height; }
} // libsim
} // sensei
#ifndef sensei_libsim_ImageProperties_h
#define sensei_libsim_ImageProperties_h
#include <string>
namespace sensei
{
namespace libsim
{
class ImageProperties
{
public:
ImageProperties();
~ImageProperties();
void SetFilename(const std::string &s);
void SetWidth(int val);
void SetHeight(int val);
void SetFormat(const std::string &s);
const std::string &GetFilename() const;
const std::string &GetFormat() const;
int GetWidth() const;
int GetHeight() const;
private:
std::string filename;
std::string format;
int width, height;
};
} // libsim
} // sensei
#endif
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