[cig-commits] r13721 - cs/cigma/trunk/src
luis at geodynamics.org
luis at geodynamics.org
Wed Dec 17 02:32:08 PST 2008
Author: luis
Date: 2008-12-17 02:32:06 -0800 (Wed, 17 Dec 2008)
New Revision: 13721
Modified:
cs/cigma/trunk/src/MeshPart.cpp
Log:
Generalized MeshPart::setPath() init method
* Look for a CellType attribute in the right place
Modified: cs/cigma/trunk/src/MeshPart.cpp
===================================================================
--- cs/cigma/trunk/src/MeshPart.cpp 2008-12-17 10:32:05 UTC (rev 13720)
+++ cs/cigma/trunk/src/MeshPart.cpp 2008-12-17 10:32:06 UTC (rev 13721)
@@ -1,5 +1,7 @@
#include "MeshPart.h"
#include "io_file_reader.h"
+#include "io_hdf5_reader.h"
+#include "io_vtk_reader.h"
#include "core_readers.h"
#include <cassert>
#include <string>
@@ -14,26 +16,23 @@
shared_ptr<MeshPart> MeshPart::New(const MeshInfo& mesh_info)
{
- TRI_LOG_STR("MeshPart::New");
+ TRI_LOG_STR("MeshPart::New()");
shared_ptr<MeshPart> mesh;
if (mesh_info.p_mesh)
{
mesh = shared_ptr<MeshPart>(new MeshPart);
+ mesh->cell_type = Cell::string2type(mesh_info.cell_type_name);
mesh->setPath(mesh_info.p_mesh);
- if (mesh->cell_type == Cell::NONE)
- {
- mesh->cell_type = Cell::string2type(mesh_info.cell_type_name);
- }
return mesh;
}
if (mesh_info.p_nc && mesh_info.p_eb)
{
mesh = shared_ptr<MeshPart>(new MeshPart);
+ mesh->cell_type = Cell::string2type(mesh_info.cell_type_name);
mesh->setPath2(mesh_info.p_nc, mesh_info.p_eb);
- mesh->cell_type = Cell::string2type(mesh_info.cell_type_name);
return mesh;
}
@@ -75,50 +74,78 @@
void MeshPart::setPath(const DataPath& p_mesh)
{
- TRI_LOG_STR("MeshPart::setPath");
+ TRI_LOG_STR("MeshPart::setPath()");
TRI_LOG(p_mesh);
- if (p_mesh)
+ string filename = p_mesh.filename();
+ string location = p_mesh.location();
+
+ shared_ptr<FileReader> reader = FileReader::New(filename, "r");
+ const FileReader::ReaderType rt = reader->getReaderType();
+
+ if (rt == FileReader::HDF5_FILE_READER)
{
- //
- // Deduce p_nc and p_eb from p_mesh
- //
+ HDF5_Reader *h5 = static_cast<HDF5_Reader*>(&(*reader));
- DataPath p_nc, p_eb;
- std::string filename = p_mesh.filename();
- std::string location = p_mesh.location();
+ bool locIsGroup = h5->locationIsGroup(location.c_str());
+ TRI_LOG(locIsGroup);
+ if (locIsGroup)
+ {
+ DataPath p_nc, p_eb;
+ p_nc.set_filename(filename);
+ p_nc.set_location(location + "/coordinates");
- // XXX: throw exception if filename doesn't load an HDF5 reader
- //
-
- // XXX: throw exception if location does not point to an HDF5 group
- //
+ p_eb.set_filename(filename);
+ p_eb.set_location(location + "/connectivity");
- // XXX: read attribute CellType from group, and call this->setCell(...)
-
- //
- // use default paths
- //
+ if (cell_type == Cell::NONE)
+ {
+ string cell_name;
+ int status = h5->readAttrString(location.c_str(), "CellType", cell_name);
+ TRI_LOG(status);
+ if (status == 0)
+ {
+ TRI_LOG(cell_name);
+ this->cell_type = Cell::string2type(cell_name);
+ }
+ }
- if (location == "/")
+ this->setPath2(p_nc, p_eb);
+ }
+ else
{
- location = "";
+ std::ostringstream stream;
+ stream << "Could not read mesh path '" << p_mesh << "' as an HDF5 group" << std::ends;
+ throw cigma::Exception("MeshPart::setPath", stream.str());
}
+ }
+ else if (rt == FileReader::VTK_FILE_READER)
+ {
+ VtkReader *vtk = static_cast<VtkReader*>(&(*reader));
+ DataPath p_nc, p_eb;
p_nc.set_filename(filename);
- p_nc.set_location(location + "/coordinates");
-
p_eb.set_filename(filename);
- p_eb.set_location(location + "/connectivity");
+ if (cell_type == Cell::NONE)
+ {
+ this->cell_type = vtk->getCellType(0);
+ }
+
this->setPath2(p_nc, p_eb);
}
- else
+ else if (rt == FileReader::TEXT_FILE_READER)
{
- string msg("Path to mesh not specified");
+ string msg("Cannot specify mesh coordinates & connectivity with a single text file");
throw cigma::Exception("MeshPart::setPath", msg);
}
+ else
+ {
+ std::ostringstream stream;
+ stream << "Invalid mesh path '" << p_mesh << "'" << std::ends;
+ throw cigma::Exception("MeshPart::setPath", stream.str());
+ }
}
void MeshPart::setPath2(const DataPath& p_nc, const DataPath& p_eb)
More information about the CIG-COMMITS
mailing list