Commit 75f73a07 authored by Edward Vigmond's avatar Edward Vigmond

Getting closer to VTU functionality.

parent c48738d9
......@@ -83,6 +83,8 @@ class PPoint: public DrawingObj
vector<bool>_allvis; //!< all true
int _maxtm; //!< maximum time
int _tm; //!< current time
GLfloat _min[3]={0,0,0},
_max[3]={0,0,0};//!< bounding box
DataClass<float>* _dynPt; //!< dynamic point data
};
......
......@@ -43,11 +43,12 @@ CXXFLAGS = -std=c++11 -g -O$(DEBUG_LEVEL) $(OMP_FLAG) -MMD -DNOMINMAX
# VTK
#VTK=1
ifdef VTK
COMMON_INC += -DUSE_VTK -I/usr/include/vtk-8.1
VTK_LSLIBS = $(shell ls /usr/lib64/libvtk*.so|grep -v Python|grep -v Java |grep -v TCL)
a = $(subst /usr/lib64/lib,-l,$(VTK_LSLIBS) )
VTK_LIBS = $(subst .so,,$(a) )
$(warning $(VTK_LIBS))
VTK_LIBDIR =/usr/lib64
VTK_INCDIR =/usr/include/vtk-8.1
COMMON_INC += -DUSE_VTK -I$(VTK_INCDIR)
VTK_LSLIBS = $(shell ls $(VTK_LIBDIR)/libvtk*.so|grep -v Python|grep -v Java |grep -v TCL)
a = $(subst $(VTK_LIBDIR)/lib,-l,$(VTK_LSLIBS) )
VTK_LIBS = $(subst .so,,$(a) )
LIBS += $(VTK_LIBS)
endif
......
......@@ -13,17 +13,17 @@
#include "logger.hpp"
#include <algorithm>
#include <queue>
#ifdef _OPENMP
#include<omp.h>
#endif
#ifdef USE_VTK
#include <vtkSmartPointer.h>
#include<vtkUnstructuredGrid.h>
#include<vtkXMLUnstructuredGridReader.h>
#endif
#ifdef _OPENMP
#include<omp.h>
#endif
struct Face {
int nsort[MAX_NUM_SURF_NODES]; //!< sorted nodes
int norig[MAX_NUM_SURF_NODES]; //!< nodes in original order
......@@ -216,10 +216,8 @@ bool Model::read( const char* fnt, bool base1, bool no_elems )
}
read_region_file( in, fn );
//LOG_TIMER("read_region_file()");
determine_regions();
//LOG_TIMER("determine_regions()");
LOG_TIMER_RESET;
add_surface_from_elem( fn );
......@@ -401,6 +399,124 @@ void Model::add_surfaces(int *elements, int count, int max_width, char *name) {
#endif // USE_HDF5
#ifdef USE_VTK
const char *VTK2CARP_etype[] = {
" ", // VTK_EMPTY_CELL = 0,
"Pt", // VTK_VERTEX = 1,
"PP", // VTK_POLY_VERTEX = 2,
"Ln", // VTK_LINE = 3,
"Ca", // VTK_POLY_LINE = 4,
"Tr", // VTK_TRIANGLE = 5,
"TS", // VTK_TRIANGLE_STRIP = 6,
"PG", // VTK_POLYGON = 7,
"Px", // VTK_PIXEL = 8,
"Qd", // VTK_QUAD = 9,
"Tt", // VTK_TETRA = 10,
"Vx", // VTK_VOXEL = 11,
"Hx", // VTK_HEXAHEDRON = 12,
"Wd", // VTK_WEDGE = 13,
"Py", // VTK_PYRAMID = 14,
"Pr", // VTK_PENTAGONAL_PRISM = 15,
"HP", // VTK_HEXAGONAL_PRISM = 16,
};
bool
Model::add_surfaces( vtkUnstructuredGrid* grid )
{
Surfaces *newSurf = new Surfaces(&pt);
newSurf->num(0);
newSurf->label("default");
_surface.push_back(newSurf);
int numCell = grid->GetNumberOfCells();
newSurf->num(numCell-_numVol);
int e=0;
for( int i=0; i<numCell; i++ ) {
const char *eletype = VTK2CARP_etype[grid->GetCellType(i)];
if( !strcmp( eletype, "Tr" ) )
_surface[0]->addele(e, new Triangle( &pt ));
else if( !strcmp( eletype, "Qd" ) )
_surface[0]->addele(e, new Quadrilateral( &pt ));
else
continue;
vtkIdType np, *cpt;
grid->GetCellPoints( i, np, cpt );
int ipt[4];
if( !strcmp( eletype, "Tr" ) ) {
ipt[0] = cpt[0];
ipt[1] = cpt[2];
ipt[2] = cpt[1];
} else if( !strcmp( eletype, "Qd" ) ) {
ipt[0] = cpt[0];
ipt[1] = cpt[3];
ipt[2] = cpt[2];
ipt[3] = cpt[1];
}
newSurf->ele(e)->define(ipt);
newSurf->ele(e)->compute_normals(0,0);
e++;
}
}
/** read in volume elements
*
* \return true if surface elements present
*/
bool
Model:: read_elements(vtkUnstructuredGrid* grid)
{
int numCell = grid->GetNumberOfCells();
_numVol = numCell;
_vol = new VolElement*[_numVol];
int ne=0;
int surfe=0;
int n[10];
int nonvol=0;
for( int i=0; i<numCell; i++ ) {
const char *eletype = VTK2CARP_etype[grid->GetCellType(i)];
vtkIdType *nvtk, nn;
grid->GetCellPoints( i, nn, nvtk );
for( int j=0; j<nn; j++ )
n[j] = nvtk[j];
int reg = 0;
if( !strcmp( eletype, "Tt" ) ) {
_vol[ne] = new Tetrahedral( &pt );
_vol[ne]->add( n, reg );
ne++;
} else if( !strcmp( eletype, "Hx" ) ) {
_vol[ne] = new Hexahedron( &pt );
_vol[ne]->add( n, reg );
ne++;
} else if( !strcmp( eletype, "Py" ) ) {
_vol[ne] = new Pyramid( &pt );
_vol[ne]->add( n, reg );
ne++;
} else if( !strcmp( eletype, "Pr" ) ) {
_vol[ne] = new Prism( &pt );
_vol[ne]->add( n, reg );
ne++;
} else if( !strcmp( eletype, "Ln" ) ) {
_cnnx->add( 1,n );
} else if( !strcmp( eletype, "Tr" ) || !strcmp( eletype, "Qd" ) ) {
// surface elements ignored
nonvol++;
surfe++;
} else {
fprintf(stderr, "Unsupported element type: %s\n", eletype);
nonvol++;
}
}
_numVol -= nonvol;
return nonvol>0;
}
bool
Model::read_vtu( const char* filename, bool no_elem )
{
......@@ -419,7 +535,27 @@ Model::read_vtu( const char* filename, bool no_elem )
p[3*i+j] = x[j];
}
pt.add( p, np );
allvis.resize(pt.num());
allvis.assign(pt.num(), true );
_file = filename;
_file.erase(_file.size()-4);
_cnnx = new Connection( &pt );
_cable = new ContCable( &pt );
if(!no_elem)
if( read_elements(grid) )
add_surfaces(grid);
determine_regions();
find_max_dim_and_bounds();
return true;
}
#endif
......@@ -434,6 +570,7 @@ void Model::find_max_dim_and_bounds()
if ( fabs(p[i+j]-offset[j])>_maxdim )
_maxdim = fabs(p[i+j]-offset[j]);
if( _vertnrml != NULL ) delete _vertnrml;
_vertnrml= new GLfloat[3*pt.num()];
int i=0;
......@@ -550,7 +687,7 @@ void Model::determine_regions()
/** add surface by selecting 2D elements from .elem file
*
* A surface will be created for each different region specified.
* Also, all elements withoyut a region specified will form a surface.
* Also, all elements without a region specified will form a surface.
*
* \param base model name
*/
......
......@@ -14,6 +14,9 @@
#ifdef USE_HDF5
#include <ch5/ch5.h>
#endif
#ifdef USE_VTK
class vtkUnstructuredGrid;
#endif
class DataOpacity;
......@@ -105,6 +108,10 @@ class Model
void add_surfaces(hid_t hdf_file);
void add_surfaces(int *elements, int count, int max_width, char *name);
#endif
#ifdef USE_VTK
bool read_elements( vtkUnstructuredGrid* grid );
bool add_surfaces( vtkUnstructuredGrid* grid );
#endif
RRegion** _region=NULL;
vector<Surfaces*> _surface;
......
......@@ -182,14 +182,13 @@ bool PPoint :: read(hid_t hdf_file)
}
// Centre model on origin
float min[3], max[3];
for (int i = 0; i < _n * 3; i += 3) {
for (int j = 0; j < 3; j++) {
if (i == 0 || _pts[i+j] > max[j]) max[j] = _pts[i+j];
if (i == 0 || _pts[i+j] < min[j]) min[j] = _pts[i+j];
if (i == 0 || _pts[i+j] > _max[j]) _max[j] = _pts[i+j];
if (i == 0 || _pts[i+j] < _min[j]) _min[j] = _pts[i+j];
}
}
for (int i = 0; i < 3; i++) _offset[i] = (min[i]+max[i])/2;
for (int i = 0; i < 3; i++) _offset[i] = (_min[i]+_max[i])/2;
_allvis.resize(info.count);
_allvis.assign(info.count, true );
......@@ -210,6 +209,16 @@ PPoint :: add( GLfloat *p, int n )
_n += n;
_pts = (GLfloat *)realloc( _pts, _n*3*sizeof(GLfloat) );
memcpy( _pts+3*(_n-n), p, n*3*sizeof(GLfloat) );
// Centre model on origin
for (int i = (_n-n)*3; i < _n * 3; i += 3) {
for (int j = 0; j < 3; j++) {
if (i == 0 || _pts[i+j] > _max[j]) _max[j] = _pts[i+j];
if (i == 0 || _pts[i+j] < _min[j]) _min[j] = _pts[i+j];
}
}
for (int i = 0; i < 3; i++) _offset[i] = (_min[i]+_max[i])/2;
_allvis.resize( _n );
_allvis.assign( _n, true );
setVis( true );
......
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