[cig-commits] r13705 - cs/cigma/trunk/src
luis at geodynamics.org
luis at geodynamics.org
Wed Dec 17 02:31:37 PST 2008
Author: luis
Date: 2008-12-17 02:31:36 -0800 (Wed, 17 Dec 2008)
New Revision: 13705
Modified:
cs/cigma/trunk/src/core_list_op.cpp
cs/cigma/trunk/src/io_vtk.cpp
cs/cigma/trunk/src/io_vtk.h
Log:
Moved vtk print function to from core_list_op.cpp to io_vtk.{h,cpp}
Modified: cs/cigma/trunk/src/core_list_op.cpp
===================================================================
--- cs/cigma/trunk/src/core_list_op.cpp 2008-12-17 10:31:35 UTC (rev 13704)
+++ cs/cigma/trunk/src/core_list_op.cpp 2008-12-17 10:31:36 UTC (rev 13705)
@@ -1,9 +1,13 @@
#include "core_list_op.h"
#include "Common.h"
#include "Filesystem.h"
+
//#include "io_hdf5_reader.h"
//#include "io_vtk_reader.h"
+#include "io_vtk.h"
+#include "io_hdf5.h"
+
// std
#include <iostream>
#include <cstdlib>
@@ -20,6 +24,7 @@
using namespace cigma;
namespace fs = boost::filesystem;
+
// ----------------------------------------------------------------------------
ListOp::ListOp()
@@ -31,9 +36,7 @@
{
}
-// ----------------------------------------------------------------------------
-
static int list_h5(const char *filename)
{
assert(filename != 0);
@@ -47,13 +50,12 @@
return ret;
}
+
static int list_vtk(const char *filename)
{
+ /*
cout << "Listing vtk file '" << filename << "'" << endl;
-/*
- assert(filename != 0);
-
VtkReader vtkreader;
vtkreader.open(filename);
@@ -124,8 +126,10 @@
}
}
- // */
return 0;
+ */
+
+ return vtk_print_contents(filename);
}
@@ -142,11 +146,10 @@
int ListOp::run()
{
- cout << "ListOp::run()" << endl;
+ TRI_LOG_STR("ListOp::run()");
- // XXX: use file magic number instead of extension?
+ // XXX: Use file magic number instead of extension?
// Create static methods in each of the respective readers
- // and
fs::path p(filename);
string ext = fs::extension(p);
Modified: cs/cigma/trunk/src/io_vtk.cpp
===================================================================
--- cs/cigma/trunk/src/io_vtk.cpp 2008-12-17 10:31:35 UTC (rev 13704)
+++ cs/cigma/trunk/src/io_vtk.cpp 2008-12-17 10:31:36 UTC (rev 13705)
@@ -54,21 +54,21 @@
return "";
}
+/* XXX: do we need a vtk_typeclass? */
-/* create a legacy reader */
-vtkDataSetReader* vtk_open(const char *filename, vtkGridType& gridType)
+
+/* create and returns a legacy reader */
+vtkDataSetReader* vtk_read_legacy(const char *filename, vtkGridType& gridType)
{
- TRI_LOG_STR("vtk_open()");
+ TRI_LOG_STR("vtk_read_legacy()");
TRI_LOG(filename);
vtkDataSetReader* legacyReader;
- int status;
legacyReader = vtkDataSetReader::New();
legacyReader->SetFileName(filename);
- status = legacyReader->OpenVTKFile();
- if (status != 0)
+ if (legacyReader->OpenVTKFile())
{
gridType = GRID_VTK;
legacyReader->Update();
@@ -76,6 +76,7 @@
else
{
gridType = GRID_NULL;
+ legacyReader->Delete();
return 0;
}
@@ -84,9 +85,9 @@
/* create an xml reader */
-vtkXMLReader* vtk_open_xml(const char *filename, vtkGridType& gridType)
+vtkXMLReader* vtk_read_xml(const char *filename, vtkGridType& gridType)
{
- TRI_LOG_STR("vtk_open_xml()");
+ TRI_LOG_STR("vtk_read_xml()");
TRI_LOG(filename);
namespace fs = boost::filesystem;
@@ -95,6 +96,9 @@
vtkXMLReader* xmlReader;
+ xmlReader = 0;
+ gridType = GRID_NULL;
+
if (ext == ".vtr")
{
xmlReader = vtkXMLRectilinearGridReader::New();
@@ -125,10 +129,20 @@
xmlReader = vtkXMLPUnstructuredGridReader::New();
gridType = GRID_PVTU;
}
- else
+
+ if (xmlReader)
{
- xmlReader = 0
- gridType = GRID_NULL;
+ int status = xmlReader->CanReadFile(filename);
+
+ if (xmlReader->CanReadFile(filename))
+ {
+ xmlReader->SetFileName(filename);
+ xmlReader->Update();
+ }
+ else
+ {
+ return 0;
+ }
}
return xmlReader;
@@ -176,5 +190,82 @@
return -1;
}
+int vtk_print_contents(const char *filename)
+{
+ TRI_LOG_STR("vtk_print_contents()");
+ TRI_LOG(filename);
+ cout << "Listing contents of VTK file '" << filename << "'" << endl;
+
+ VtkReader reader;
+ reader.open(filename, "r");
+
+ if (reader.dataset == 0)
+ {
+ return -1;
+ }
+
+ vtkDataSet* dataset = reader.dataset;
+ vtkPointData* pointData = dataset->GetPointData();
+ vtkCellData* cellData = dataset->GetCellData();
+
+ if (false)
+ {
+ pointData->PrintSelf(cout, 0);
+ cellData->PrintSelf(cout, 0);
+ }
+
+ int nno = dataset->GetNumberOfPoints();
+ int nel = dataset->GetNumberOfCells();
+
+ if (nno > 0) { cout << "Points = " << nno << endl; }
+ if (nel > 0) { cout << "Cells = " << nel << endl; }
+
+ int i,n;
+ int numArrays, numTuples, numComponents;
+
+ numArrays = pointData->GetNumberOfArrays();
+ if (numArrays > 0)
+ {
+ for (i = 0; i < numArrays; i++)
+ {
+ vtkDataArray* dataArray = pointData->GetArray(i);
+ const char *name = pointData->GetArrayName(i);
+ numTuples = dataArray->GetNumberOfTuples();
+ numComponents = dataArray->GetNumberOfComponents();
+ cout << "PointDataArray[" << i << "] = " << name;
+ //cout << " " << dataArray->GetClassName();
+ cout << " (" << numTuples << " x " << numComponents << ")";
+ cout << endl;
+ }
+ }
+
+ numArrays = cellData->GetNumberOfArrays();
+ if (numArrays > 0)
+ {
+ for (i = 0; i < numArrays; i++)
+ {
+ vtkDataArray* dataArray = cellData->GetArray(i);
+ const char *name = cellData->GetArrayName(i);
+ numTuples = dataArray->GetNumberOfTuples();
+ numComponents = dataArray->GetNumberOfComponents();
+ cout << "CellDataArray[" << i << "] = " << name;
+ //cout << " " << dataArray->GetClassName();
+ cout << " (" << numTuples << " x " << numComponents << ")";
+ cout << endl;
+ }
+ }
+
+ return 0;
+}
+
+#else
+
+
+int vtk_print_contents(const char *filename)
+{
+ throw cigma::Exception("vtk_print_contents", "Error: Cigma not configured with VTK library", 1);
+ return -1;
+}
+
#endif /* HAVE_VTK */
Modified: cs/cigma/trunk/src/io_vtk.h
===================================================================
--- cs/cigma/trunk/src/io_vtk.h 2008-12-17 10:31:35 UTC (rev 13704)
+++ cs/cigma/trunk/src/io_vtk.h 2008-12-17 10:31:36 UTC (rev 13705)
@@ -18,6 +18,10 @@
} vtkGridType;
+int vtk_print_contents(const char *filename);
+
+
+
#ifdef HAVE_VTK
#include <string>
@@ -41,6 +45,7 @@
#include "vtkDataSet.h"
#include "vtkPointData.h"
+#include "vtkCellData.h"
#include "vtkDataArray.h"
#include "vtkDataArraySelection.h"
@@ -60,17 +65,18 @@
std::string vtk_datatype_name(int datatype);
-vtkDataSetReader* vtk_open_legacy(const char *filename, vtkGridType& gridType);
+vtkDataSetReader* vtk_read_legacy(const char *filename, vtkGridType& gridType);
-vtkXMLReader* vtk_open_xml(const char *filename, vtkGridType& gridType);
+vtkXMLReader* vtk_read_xml(const char *filename, vtkGridType& gridType);
int vtk_celldim(int cellType);
+int vtk_print_contents(const char *filename);
template <typename T>
-int vtk_read_array(vtkDataSet* dataset, const char *loc, T** data, int *num, int *dim)
+int vtk_read_pointdata(vtkDataSet* dataset, const char *loc, T** data, int *num, int *dim)
{
- TRI_LOG_STR("vtk_read_array()");
+ TRI_LOG_STR("vtk_read_pointdata()");
TRI_LOG(loc);
if (dataset == 0)
@@ -88,7 +94,7 @@
if (pointData == 0)
{
- throw cigma::Exception("vtk_read_array", "Could not read VTK Point Data from dataset", 1);
+ throw cigma::Exception("vtk_read_pointdata", "Could not read VTK Point Data from dataset", 1);
}
if (pointData->HasArray(loc) == 1)
@@ -99,7 +105,7 @@
{
std::ostringstream stream;
stream << "failed to get array '" << loc << "' from VTK Point Data" << std::ends;
- throw cigma::Exception("vtk_read_array", stream.str(), 2);
+ throw cigma::Exception("vtk_read_pointdata", stream.str(), 2);
}
int datatype = dataArray->GetDataType();
@@ -116,7 +122,7 @@
<< name << " array, expected "
<< expected << " array)"
<< std::ends;
- throw cigma::Exception("vtk_read_array", stream.str(), 3);
+ throw cigma::Exception("vtk_read_pointdata", stream.str(), 3);
}
npts = dataArray->GetNumberOfTuples();
@@ -186,14 +192,14 @@
std::ostringstream stream;
std::string name = vtk_datatype_name(datatype);
stream << "Need handler for " << name << " datatype" << std::ends;
- throw cigma::Exception("vtk_read_array", stream.str(), 4);
+ throw cigma::Exception("vtk_read_pointdata", stream.str(), 4);
}
}
else
{
std::ostringstream stream;
stream << "array '" << loc << "' does not exist" << std::ends;
- throw cigma::Exception("vtk_read_array", stream.str(), 5);
+ throw cigma::Exception("vtk_read_pointdata", stream.str(), 5);
}
*data = array;
More information about the CIG-COMMITS
mailing list