Commit 65d0a7d8 authored by Edward Vigmond's avatar Edward Vigmond
Browse files

You can now save the regions extracted into a surf file.

Surf files have been introduced as a generalized replacement for tri
files.
parent 826c4386
......@@ -4,7 +4,7 @@ HOSTMACHINE := $(shell uname)
FLTK_INC := $(shell fltk-config --use-gl --cxxflags)
FLTK_LD_FLAGS := $(shell fltk-config --use-gl --ldflags)
COMMON_LIBS = -lredblack -lpng -lpthread -lm -lz
COMMON_INC = -I. -O0 -g -DOBJ_CLASS -D_REENTRANT
COMMON_INC = -I. -O0 -g -DOBJ_CLASS -pg -D_REENTRANT
ifeq ($(HOSTMACHINE),Linux)
LIBS = $(FLTK_LD_FLAGS) $(COMMON_LIBS)
......
......@@ -7,7 +7,8 @@
#include "gl2ps.h"
#include <redblack.h>
#include "VecData.h"
#include <sstream>
#include <FL/filename.H>
struct Face {
int nsort[MAX_NUM_SURF_NODES]; //!< sorted nodes
......@@ -84,6 +85,7 @@ Model::Model(Colourscale *cs, DataOpacity *dopac ):
const int bufsize=1024;
bool Model::read( const char* fnt, bool base1, bool no_elems )
{
_file = fnt;
char fn[bufsize];
strcpy( fn, fnt );
gzFile in;
......@@ -117,10 +119,9 @@ bool Model::read( const char* fnt, bool base1, bool no_elems )
if( !no_elems ) read_elem_file( fn );
read_region_file( in, fn );
determine_regions();
add_region_surfaces();
//_triele = new Triangle( &pt );
add_surface_from_tri( fn );
add_surface_from_surf( fn );
add_surface_from_elem( fn );
// find maximum dimension and bounding box
......@@ -306,8 +307,12 @@ int Model::add_surface_from_elem( const char *fn )
}
gzclose( in );
for ( int s=oldnumSurf; s<_surface.size(); s++ )
for ( int s=oldnumSurf; s<_surface.size(); s++ ) {
_surface[s]->determine_vert_norms( pt );
ostringstream slabel(fname);
slabel << s-oldnumSurf;
_surface[s]->label( slabel.str() );
}
return _surface.size();
}
......@@ -323,6 +328,7 @@ int Model::add_region_surfaces()
// set up matrix to hold element faces
int **faces = new int *[MAX_NUM_SURF];
for( int i=0; i<MAX_NUM_SURF; i++ ) faces[i] = new int[MAX_NUM_SURF_NODES+1];
int numNewSurf=0;
for( int r=0; r<_numReg; r++ ) {
......@@ -352,6 +358,7 @@ int Model::add_region_surfaces()
if( numface ) { // convert the left over faces into a surface
numNewSurf++;
rbl = rbopenlist( facetree );
_surface.push_back( new Surfaces( &pt ) );
......@@ -371,15 +378,82 @@ int Model::add_region_surfaces()
_surface.back()->ele(e)->define( newface->norig );
_surface.back()->ele(e)->compute_normals(0,0);
delete newface; // mo longer needed
delete newface; // no longer needed
}
_surface.back()->determine_vert_norms( pt );
ostringstream regnum;
regnum << "Reg " << r;
_surface.back()->label( regnum.str() );
rbcloselist( rbl );
rbdestroy( facetree );
}
}
for( int i=0; i<MAX_NUM_SURF; i++ ) delete[] faces[i];
delete[] faces;
return numNewSurf;
}
/** add a surface by reading in a .surf file
*
* \param fn file containing surface elements
*
* \return the \#surfaces added, -1 if not successful
*/
int Model::add_surface_from_surf( const char *fn )
{
/* determine file name */
gzFile in;
string fname(fn);
if ( (in=gzopen( fname.c_str(), "r" )) == NULL ) {
fname += "surf";
if ( (in=gzopen( fname.c_str(), "r" )) == NULL ) {
fname += ".gz";
if ( (in=gzopen( fname.c_str(), "r" )) == NULL ) {
return -1;
}
}
}
int nd[5], nele;
char buff[bufsize];
int surfnum = 0;
char surflabel[bufsize];
while ( gzgets(in,buff,bufsize)!=Z_NULL && sscanf(buff, "%d", &nele )==1 ) {
_surface.push_back( new Surfaces( &pt ) );
// use specified surface label if available
if( sscanf( buff, "%d %s", &nele, surflabel ) != 2 )
sprintf( surflabel, "%s:%d", fl_filename_name(fname.c_str()), surfnum );
_surface.back()->label( surflabel );
_surface.back()->num(nele);
for ( int i=0; i<nele; i++ ) {
int nl[5];
char etype[12];
if ( gzgets(in,buff,bufsize) == Z_NULL ||
sscanf(buff, "%s %d %d %d", etype, nl, nl+1, nl+2, nl+3, nl+4 ) < 4 ) {
_surface.pop_back();
return surfnum;
}
if( !strcmp(etype, "Tr" ) )
_surface.back()->ele(i) = new Triangle( &pt );
else if( !strcmp(etype, "Qd") )
_surface.back()->ele(i) = new Quadrilateral( &pt );
else {
_surface.pop_back();
return surfnum;
}
_surface.back()->ele(i)->define(nl);
_surface.back()->ele(i)->compute_normals(0,0);
}
_surface.back()->determine_vert_norms( pt );
surfnum++;
}
return surfnum;
}
......@@ -416,10 +490,19 @@ int Model::add_surface_from_tri( const char *fn )
char buff[bufsize];
gzgets(in,buff,bufsize);
bool multi_surface = sscanf( buff, "%d %d %d", &ntri, nd+1, nd+2 ) < 3;
int surfnum = 0;
if ( multi_surface ) {
do {
_surface.push_back( new Surfaces( &pt ) );
// use specified surface label if available
char surflabel[1024];
if( sscanf( buff, "%d %s", &ntri, surflabel ) != 2 )
sprintf( surflabel, "%s:%d", fl_filename_name(fname.c_str()), surfnum );
_surface.back()->label( surflabel );
_surface.back()->num(ntri);
for ( int i=0; i<ntri; i++ ) {
_surface.back()->ele(i) = new Triangle( &pt );
......@@ -427,30 +510,42 @@ int Model::add_surface_from_tri( const char *fn )
if ( gzgets(in,buff,bufsize) == Z_NULL ||
sscanf(buff, "%d %d %d", nl, nl+1, nl+2 ) < 3 ) {
_surface.pop_back();
return numSurf();
return surfnum;
}
_surface.back()->ele(i)->define(nl);
_surface.back()->ele(i)->compute_normals(0,0);
}
_surface.back()->determine_vert_norms( pt );
surfnum++;
} while ( gzgets(in,buff,bufsize)!=Z_NULL && sscanf(buff, "%d",&ntri)==1 );
} else {
} else { // 1 surface
int nl[3];
nl[0]=ntri;nl[1]=nd[1];nl[2]=nd[2];
_surface.push_back( new Surfaces( &pt ) );
int curele = 0;
do {
if( sscanf(buff, "%d %d %d",nl, nl+1, nl+2) < 3 ) {
if( !curele ) {
_surface.pop_back();
return -1;
} else
break;
}
#define ELEINC 10000
if( !(curele%ELEINC) ) _surface.back()->num(curele+ELEINC);
_surface.back()->ele(curele) = new Triangle( &pt );
_surface.back()->ele(curele)->define(nl);
_surface.back()->ele(curele++)->compute_normals(0,0);
}while( gzgets(in,buff,bufsize)!=Z_NULL &&
sscanf(buff, "%d %d %d",nl, nl+1, nl+2)>=3 );
}while( gzgets(in,buff,bufsize)!=Z_NULL );
_surface.back()->num(curele);
_surface.back()->determine_vert_norms( pt );
ostringstream slabel(fname);
_surface.back()->label( slabel.str() );
surfnum++;
}
return _surface.size();
return surfnum;
}
......
......@@ -22,6 +22,8 @@ class Model
~Model();
bool read(const char *fn, bool base1, bool no_elems);
int add_surface_from_tri( const char * );
int add_surface_from_surf( const char * );
int add_region_surfaces( void );
inline int reg_first( int s, Object_t t ){return _region[s]->first(t); }
Surfaces* surface(int s){ return _surface[s]; }
void surfKill( int s );
......@@ -82,10 +84,10 @@ class Model
void determine_regions();
bool read_elem_file(const char *);
int add_surface_from_elem( const char *fn );
int add_region_surfaces( void );
vector<bool> allvis;
int _numtm;
int new_region_label();
string _file; //!< base file name
};
#endif
......@@ -4,7 +4,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "DrawingObjects.h"
#include <string>
class Surfaces
{
......@@ -29,7 +29,9 @@ class Surfaces
vector<SurfaceElement*>& ele(){return _ele;}
void draw(GLfloat*,Colourscale*,DATA_TYPE*,int,
dataOpac*,const GLfloat*);
void register_vertices( vector<bool>& );
void register_vertices( vector<bool>& );
void label( string s ){ _label=s; }
string label( void ) { return _label; }
protected:
Point *_p;
GLfloat _fillcolor[4];
......@@ -40,7 +42,7 @@ class Surfaces
GLfloat* _vertnorm; //!< vertex normals
int* _vert; //!< vertices for which normals are computed
vector<SurfaceElement*> _ele; //!< list of elelments to draw
int label;
string _label;
};
#endif
......@@ -672,11 +672,15 @@ void TBmeshWin :: read_model( Fl_Window *flwindow, const char* fnt,
/** add a surface by reading in a .tri file, also try reading a normal file
*
* \param file file containing tri's
*
* \return \#surfaces added
*/
int TBmeshWin :: add_surface( const char *fn )
{
model->add_surface_from_tri( fn );
return model->numSurf();
int nsa;
if ( (nsa=model->add_surface_from_tri( fn ))<=0 )
nsa = model->add_surface_from_surf( fn );
return nsa;
}
......
......@@ -171,9 +171,7 @@ main( int argc, char *argv[] )
win.trackballwin->show();
for ( int i=0; i<win.trackballwin->model->numSurf(); i++ ) {
char s[256];
sprintf( s, "%d", i );
control.surflist->add( s, 1 );
control.surflist->add( win.trackballwin->model->surface(i)->label().c_str(), 1 );
}
if ( vectordata ) control.vectorgrp->activate();
control.tethi->maximum( win.trackballwin->model->numVol()-1 );
......
......@@ -79,7 +79,7 @@ volume elements are tagged, elements with no direction will be region~0,
and other elements will be region~1.
Surfaces may be formed from collections of two-dimensional elements.
Surfaces are defined by Triangle files (see \S\ref{sec:tris}).
Surfaces are defined by surface element files (see \S\ref{sec:surffile}).
Also, surfaces are defined if there are any 2D elements in an \texttt{elem}
file (see \S\ref{sec:elem}).
In the latter case,
......@@ -148,26 +148,58 @@ vertex#1 vertex#2
vertex#1 vertex#2
\end{verbatim}
\subsection{Triangles}
\subsection{Surface Elements}
\label{sec:surffile}
These files are a subset of the more general volume elements
with the suffix ``.surf''.
They may define several surfaces in one file.
Any 2-dimensional element can be specified.
labels are any sequence of characters not including white space.
The file has the following format:
\begin{verbatim}
number_elements_in_surface0 label_for_surface0
Tr vertex0 vertex1 vertex2 float
Qd vertex0 vertex1 vertex2 vertex3 float
.
.
.
Qd vertex0 vertex1 vertex2 vertex3 float
number_eleemnts_in_surface1 label_for_surface1
Tr vertex0 vertex1 vertex2 float
Tr vertex0 vertex1 vertex2 float
.
.
.
number_elements_in_surfaceN label_for_surfaceN
Qd vertex0 vertex1 vertex2 vertex3 float
Tr vertex0 vertex1 vertex2 float
.
.
.
Tr vertex0 vertex1 vertex2 float
\end{verbatim}
\subsubsection{Triangles}
\label{sec:tris}
Triangles are defined on a shell by shell basis
in a file with the extension ``.tris'' or ``.tri''
Triangle files are deprecated.
They are defined in a file with the extension ``.tris'' or ``.tri''
which has the following format:
\begin{verbatim}
number_triangles_in_shell0
number_triangles_in_surface0 label_for_surface0
vertex0 vertex1 vertex2 float
vertex0 vertex1 vertex2 float
.
.
.
vertex0 vertex1 vertex2 float
number_triangles_in_shell1
number_triangles_in_surface1 label_for_surface1
vertex0 vertex1 vertex2 float
vertex0 vertex1 vertex2 float
.
.
.
number_triangles_in_shellN
number_triangles_in_surfaceN label_for_surfaceN
vertex0 vertex1 vertex2 float
vertex0 vertex1 vertex2 float
.
......
......@@ -59,7 +59,7 @@ class Controls {open
} {
Fl_Window window {
label {Meshalyzer Controls} open
xywh {359 50 350 650} type Double box UP_BOX
xywh {5 77 350 650} type Double box UP_BOX
code0 {\#include <FL/Fl_Color_Chooser.h>}
code1 {\#include "VecData.h"} visible
} {
......@@ -67,24 +67,55 @@ class Controls {open
xywh {0 -1 350 30} labelcolor 1
} {
Submenu {} {
label File
label File open
xywh {0 0 100 20}
} {
MenuItem {} {
label {Add surface}
callback {char *fn=fl_file_chooser("Surface", "*.tri",NULL);
callback {char *fn=fl_file_chooser("Surface", "*.{tris,surf,tri}",NULL);
int sn;
if( fn != NULL ) if( (sn=mwtb->add_surface( fn ))>=0 ){
for( int s=surflist->nitems(); s<sn; s++ ) {
char surfno[100];
sprintf( surfno, "%d", s );
surflist->add(surfno,1);
if( fn != NULL ) {
if( (sn=mwtb->add_surface(fn))>0 ) {
for( int s=0; s<sn; s++ ) {
surflist->add(mwtb->model->surface(surflist->nitems())->label().c_str(),1);
}
elehi->maximum(mwtb->model->number(SurfEle)-1);
mwtb->redraw();
surflist->redraw();
}
elehi->maximum(mwtb->model->number(SurfEle)-1);
}}
xywh {0 0 100 20}
}
MenuItem {} {
label {Compute surfaces}
callback {int nsa=mwtb->model->add_region_surfaces();
int ns = mwtb->model->numSurf();
for( int i=ns-nsa; i<ns; i++ )
surflist->add( mwtb->model->surface(i)->label().c_str(),1);
surflist->redraw();
char *fn;
if( fn=fl_file_chooser( "Save surface file as:", "*.{tri,surf}*", "region.surf" )){
fl_cursor(FL_CURSOR_WAIT );
ofstream outf(fn);
for( int i=ns-nsa; i<ns; i++ ) {
SurfaceElement *e;
outf << mwtb->model->surface(i)->num() << endl;
for( int j=0; j<mwtb->model->surface(i)->num();j++ ) {
e = mwtb->model->element(i,j);
const int* n=e->obj();
if( e->ptsPerObj()==3 )
outf << "Tr";
else
outf << "Qd";
for( int k=0; k< e->ptsPerObj(); k++ )
outf << " " << n[k];
outf << endl;
}
}
fl_cursor(FL_CURSOR_DEFAULT);
mwtb->redraw();
surflist->redraw();
}}
xywh {0 0 100 20} divider
xywh {0 0 30 20} divider
}
MenuItem {} {
label {Read data}
......@@ -367,7 +398,7 @@ mwtb->trackball.size = md;mwtb->redraw();}
}
}
Submenu {} {
label Data open
label Data
xywh {0 0 100 20}
} {
MenuItem {} {
......@@ -619,12 +650,12 @@ op->win->show();}
xywh {260 165 70 25} labelsize 12
}
}
Fl_Tabs tabwidget {
Fl_Tabs tabwidget {open
xywh {10 270 330 215} align 0
} {
Fl_Group hilightgrp {
label Highlight selected
xywh {10 305 330 170} labelfont 1 labelsize 12 labelcolor 121 align 4
label Highlight
xywh {10 305 330 170} labelfont 1 labelsize 12 labelcolor 121 align 4 hide
} {
Fl_Value_Input tethi {
label {Tetrahedron:}
......@@ -938,8 +969,8 @@ mwtb->redraw();}
}
}
Fl_Group surfgrp {
label Surface
xywh {15 310 315 175} labelsize 12 labelcolor 90 hide
label Surface open
xywh {15 310 315 175} labelsize 12 labelcolor 90
} {
Fl_Light_Button surfvisbut {
label visible
......@@ -1207,8 +1238,7 @@ for( int i=1; i<=reglist->nitems(); i++ )
sel[i-1] = reglist->checked(i);
return sel;} {}
}
Function {save_state()} {open
} {
Function {save_state()} {} {
code {char *fn = fl_file_chooser("meshalyzer state file","*.mshz",NULL);
if( fn==NULL) return;
string xfn( fn );
......@@ -1544,16 +1574,16 @@ for( int i=1; i<=surflist->nitems(); i++ )
if( surflist->checked(i) )
lst.push_back(i-1);} {}
}
Function {refresh_surflist()} {} {
Function {refresh_surflist()} {open
} {
code {surflist->clear();
for( int s=0; s<mwtb->model->numSurf(); s++ ) {
char surfno[100];
sprintf( surfno, "%d", s );
surflist->add(surfno,1);
surflist->add(mwtb->model->surface(s)->label().c_str(),1);
}
elehi->maximum(mwtb->model->number(SurfEle)-1);
mwtb->redraw();
surflist->redraw();} {}
surflist->redraw();} {selected
}
}
}
......
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