Commit a244b5c0 authored by whitlocb's avatar whitlocb
Browse files

Serve up 1D rectilinear grids as curve variables from VTK files. Enhance the...

Serve up 1D rectilinear grids as curve variables from VTK files. Enhance the rectilinear grid mapper to plot them.



git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@16535 18c085ea-50e0-402c-830e-de6fd14e8384
parent c767a472
......@@ -382,6 +382,9 @@ void vtkOpenGLRectilinearGridMapper::Render(vtkRenderer *ren, vtkActor *act)
// Brad Whitlock, Tue Aug 9 14:15:25 PDT 2011
// I changed how we do 1D texturing so it is compatible with the new VTK.
//
// Brad Whitlock, Wed Oct 26 12:29:40 PDT 2011
// Add support for 1D rectilinear (Nx, 1, 1 case) grids as lines.
//
// ****************************************************************************
int vtkOpenGLRectilinearGridMapper::Draw(vtkRenderer *ren, vtkActor *act)
......@@ -400,6 +403,7 @@ int vtkOpenGLRectilinearGridMapper::Draw(vtkRenderer *ren, vtkActor *act)
bool flatI = (dims[0] <= 1);
bool flatJ = (dims[1] <= 1);
bool flatK = (dims[2] <= 1);
if (!flatI && !flatJ && !flatK)
{
vtkErrorMacro("One of the dimensions must be flat!!\n"
......@@ -535,6 +539,33 @@ int vtkOpenGLRectilinearGridMapper::Draw(vtkRenderer *ren, vtkActor *act)
if(this->ColorCoordinates != NULL)
texCoords = (const float *)this->ColorCoordinates->GetVoidPointer(0);
if(!flatI && flatJ && flatK)
{
// Draw a curve
glBegin(GL_LINE_STRIP);
if(colors == NULL && texCoords == NULL)
{
for(int i = 0; i < dims[0]; ++i)
glVertex3f(X[i], 0.f, 0.f);
}
else
{
for(int i = 0; i < dims[0]; ++i)
{
if(nodeData)
{
if(texCoords != NULL)
glTexCoord1f(texCoords[i]);
else if(colors != NULL)
glColor4ubv(colors + 4*i);
}
glVertex3f(X[i], 0.f, 0.f);
}
}
glEnd();
}
else
{
glBegin(GL_QUADS);
for (int j = 0 ; j < slowDim-1 ; j++)
for (int i = 0 ; i < fastDim-1 ; i++)
......@@ -632,6 +663,7 @@ int vtkOpenGLRectilinearGridMapper::Draw(vtkRenderer *ren, vtkActor *act)
}
}
glEnd();
}
if (transform)
glPopMatrix();
......
......@@ -67,6 +67,8 @@
#include <InvalidVariableException.h>
#include <InvalidFilesException.h>
#include <vtkVisItUtility.h>
#include <map>
#include <string>
#include <vector>
......@@ -165,6 +167,9 @@ avtVTKFileFormat::avtVTKFileFormat(const char *fname, DBOptionsAttributes *)
// Mark C. Miller, Thu Sep 15 19:45:51 PDT 2005
// Freed matvarname
//
// Brad Whitlock, Wed Oct 26 11:03:14 PDT 2011
// Delete curves in vtkCurves.
//
// ****************************************************************************
avtVTKFileFormat::~avtVTKFileFormat()
......@@ -179,6 +184,11 @@ avtVTKFileFormat::~avtVTKFileFormat()
free(matvarname);
matvarname = NULL;
}
for(std::map<std::string, vtkRectilinearGrid *>::iterator pos = vtkCurves.begin();
pos != vtkCurves.end(); ++pos)
{
pos->second->Delete();
}
}
......@@ -222,6 +232,9 @@ avtVTKFileFormat::~avtVTKFileFormat()
// Kathleen Bonnell, Wed Jul 9 18:13:20 PDT 2008
// Retrieve CYCLE from FieldData if available.
//
// Brad Whitlock, Wed Oct 26 11:04:50 PDT 2011
// Create curves for 1D rectilinear grids.
//
// ****************************************************************************
void
......@@ -373,9 +386,98 @@ avtVTKFileFormat::ReadInDataset(void)
//
dataset = ConvertStructuredPointsToRGrid((vtkStructuredPoints*)dataset);
}
if(dataset->GetDataObjectType() == VTK_RECTILINEAR_GRID)
{
vtkRectilinearGrid *rgrid = vtkRectilinearGrid::SafeDownCast(dataset);
int dims[3];
rgrid->GetDimensions(dims);
if(dims[0] > 0 && dims[1] <= 1 && dims[2] <= 1)
{
// Make some curves from this dataset.
CreateCurves(rgrid);
}
}
readInDataset = true;
}
// ****************************************************************************
// Method: avtVTKFileFormat::CreateCurves
//
// Purpose:
// Create curve datasets based on the input rectilinear grid.
//
// Arguments:
// rgrid : The rectilinear grid from which to create curves.
//
// Returns:
//
// Note: vtkCurves gets the new datasets.
//
// Programmer: Brad Whitlock
// Creation: Wed Oct 26 11:01:44 PDT 2011
//
// Modifications:
//
// ****************************************************************************
void
avtVTKFileFormat::CreateCurves(vtkRectilinearGrid *rgrid)
{
vtkDataArray *xc = rgrid->GetXCoordinates();
int nPts = xc->GetNumberOfTuples();
for(int i = 0; i < rgrid->GetPointData()->GetNumberOfArrays(); ++i)
{
vtkDataArray *arr = rgrid->GetPointData()->GetArray(i);
if(arr->GetNumberOfComponents() == 1)
{
vtkRectilinearGrid *curve = vtkVisItUtility::Create1DRGrid(nPts,VTK_FLOAT);
vtkDataArray *curve_xc = curve->GetXCoordinates();
vtkFloatArray *curve_yc = vtkFloatArray::New();
curve_yc->SetName(arr->GetName());
curve_yc->SetNumberOfTuples(nPts);
for(vtkIdType j = 0; j < nPts; ++j)
{
curve_xc->SetTuple1(j, xc->GetTuple1(j));
curve_yc->SetTuple1(j, arr->GetTuple1(j));
}
curve->GetPointData()->SetScalars(curve_yc);
curve_yc->Delete();
vtkCurves[std::string("curve_") + std::string(arr->GetName())] = curve;
}
}
for(int i = 0; i < rgrid->GetCellData()->GetNumberOfArrays(); ++i)
{
vtkDataArray *arr = rgrid->GetCellData()->GetArray(i);
if(arr->GetNumberOfComponents() == 1)
{
vtkRectilinearGrid *curve = vtkVisItUtility::Create1DRGrid(nPts,VTK_FLOAT);
vtkDataArray *curve_xc = curve->GetXCoordinates();
for(vtkIdType j = 0; j < nPts; ++j)
curve_xc->SetTuple1(j, xc->GetTuple1(j));
int nCells = nPts-1;
int idx = 0;
vtkFloatArray *curve_yc = vtkFloatArray::New();
curve_yc->SetName(arr->GetName());
curve_yc->SetNumberOfTuples(nPts);
curve_yc->SetTuple1(idx++, arr->GetTuple1(0));
for(vtkIdType j = 0; j < nCells-1; ++j)
curve_yc->SetTuple1(idx++, (arr->GetTuple1(j) + arr->GetTuple1(j+1)) / 2.);
curve_yc->SetTuple1(idx++, arr->GetTuple1(nCells-1));
curve->GetPointData()->SetScalars(curve_yc);
curve_yc->Delete();
vtkCurves[std::string("curve_") + std::string(arr->GetName())] = curve;
}
}
}
// ****************************************************************************
// Method: avtVTKFileFormat::GetAuxiliaryData
//
......@@ -498,10 +600,12 @@ avtVTKFileFormat::GetAuxiliaryData(const char *var,
// Creation: February 23, 2001
//
// Modifications:
//
// Hank Childs, Tue Mar 26 13:33:43 PST 2002
// Add a reference so that reference counting tricks work.
//
// Brad Whitlock, Wed Oct 26 11:08:31 PDT 2011
// Return curves.
//
// ****************************************************************************
vtkDataSet *
......@@ -509,14 +613,22 @@ avtVTKFileFormat::GetMesh(const char *mesh)
{
debug5 << "Getting mesh from VTK file " << filename << endl;
if (strcmp(mesh, MESHNAME) != 0)
if (!readInDataset)
{
EXCEPTION1(InvalidVariableException, mesh);
ReadInDataset();
}
if (!readInDataset)
// If the requested mesh is a curve, return it.
std::map<std::string, vtkRectilinearGrid *>::iterator pos = vtkCurves.find(mesh);
if(pos != vtkCurves.end())
{
ReadInDataset();
pos->second->Register(NULL);
return pos->second;
}
if (strcmp(mesh, MESHNAME) != 0)
{
EXCEPTION1(InvalidVariableException, mesh);
}
//
......@@ -772,6 +884,9 @@ avtVTKFileFormat::FreeUpResources(void)
// Hank Childs, Wed Sep 14 16:29:19 PDT 2011
// Improve handling of ghost data.
//
// Brad Whitlock, Wed Oct 26 11:12:17 PDT 2011
// Add metadata for curves.
//
// ****************************************************************************
void
......@@ -837,6 +952,11 @@ avtVTKFileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData *md)
<< "declaring this a point mesh." << endl;
topo = 0;
}
else if(myType == VTK_LINE)
{
debug5 << "The mesh contains all lines, set topo=1" << endl;
topo = 1;
}
}
types->Delete();
......@@ -930,6 +1050,16 @@ avtVTKFileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData *md)
md->Add(mesh);
std::map<std::string, vtkRectilinearGrid *>::iterator pos;
for(pos = vtkCurves.begin(); pos != vtkCurves.end(); ++pos)
{
avtCurveMetaData *curve = new avtCurveMetaData;
curve->name = pos->first;
curve->hasSpatialExtents = false;
curve->hasDataExtents = false;
md->Add(curve);
}
int nvars = 0;
for (i = 0 ; i < dataset->GetPointData()->GetNumberOfArrays() ; i++)
......
......@@ -44,7 +44,10 @@
#define AVT_VTK_FILE_FORMAT_H
#include <avtSTSDFileFormat.h>
#include <map>
#include <string>
class vtkRectilinearGrid;
class vtkStructuredPoints;
class DBOptionsAttributes;
......@@ -88,6 +91,9 @@ class DBOptionsAttributes;
// Kathleen Bonnell, Wed Jul 9 18:13:50 PDT 2008
// Added GetCycle method.
//
// Brad Whitlock, Wed Oct 26 11:01:00 PDT 2011
// I added vtkCurves.
//
// ****************************************************************************
class avtVTKFileFormat : public avtSTSDFileFormat
......@@ -126,8 +132,11 @@ class avtVTKFileFormat : public avtSTSDFileFormat
std::string extension;
std::map<std::string, vtkRectilinearGrid *> vtkCurves;
void ReadInDataset(void);
vtkDataSet *ConvertStructuredPointsToRGrid(vtkStructuredPoints *);
void CreateCurves(vtkRectilinearGrid *rgrid);
};
......
......@@ -65,6 +65,7 @@ enhancements and bug-fixes that were added to this release.</p>
<li>VisIt can now read XSF (XCrySDen Structure) files containing periodic structures (molecule, polymer, slab, and crystal with lattice vectors) and general grids.</li>
<li>The Tecplot reader now supports shared variables, in both its ASCII and binary flavors. It also allows use of the strand ID, though it still assumes zones are equivalent to domains.</li>
<li>Tecplot also now supports database options which allow the user to override automatic guessing of coordinate variables.</li>
<li>VisIt's VTK reader now serves up 1D rectilinear grids as curve variables as well as scalar variables, making them plottable using the Curve plot.</li>
</ul>
<a name="Plot_changes"></a>
......
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