Skip to content
Snippets Groups Projects
Commit 33715bae authored by Brian Patenaude's avatar Brian Patenaude
Browse files

initial import

parents
No related branches found
Tags intial
No related merge requests found
Makefile 0 → 100644
# $Id$
include ${FSLCONFDIR}/default.mk
PROJNAME = fslvtkio
USRINCFLAGS = -I${INC_NEWMAT} -I${INC_ZLIB}
USRLDFLAGS = -L${LIB_NEWMAT} -L${LIB_ZLIB}
LIBS= -lmeshclass -lnewimage -lmiscmaths -lfslio -lniftiio -lznz -lnewmat -lutils -lz
SHAPEOBJS=fslvtkio.o
MODELOBJS=fslvtkio.o
DBGFLAGS=-g
ARCHFLAGS =
ARCHLDFLAGS =
all: fslvtkio.a
fslvtkio.a: ${SHAPEOBJS}
${AR} -r libfslvtkio.a ${SHAPEOBJS}
#include "fslvtkio.h"
#include "meshclass/meshclass.h"
#include "newimage/newimageall.h"
#include <sstream>
using namespace std;
using namespace NEWIMAGE;
using namespace mesh;
namespace fslvtkio {
fslvtkIO::fslvtkIO(){
DataType="POLYDATA";
scalarsName="Scalars";
vectorsName="Vectors";
}
fslvtkIO::~fslvtkIO(){
}
void fslvtkIO::setMesh(Mesh m){
//set points
//assume 3 dimensions
Points.ReSize(m._points.size(),3);
int count=0;
for (vector<Mpoint*>::iterator i = m._points.begin(); i!=m._points.end(); i++ )
{
Points.element(count,0)=(*i)->get_coord().X;
Points.element(count,1)=(*i)->get_coord().Y;
Points.element(count,2)=(*i)->get_coord().Z;
count++;
}
//set polygons, assumes eacxh vertex has 3 connections
Polygons.ReSize(m._triangles.size(),3);
count=0;
for ( list<Triangle*>::const_iterator i=m._triangles.begin(); i!=m._triangles.end(); i++) {
Polygons.element(count,0)=(*i)->get_vertice(0)->get_no();
Polygons.element(count,1)=(*i)->get_vertice(1)->get_no();
Polygons.element(count,2)=(*i)->get_vertice(2)->get_no();
count++;
}
}
void fslvtkIO::setPoints(Matrix m){
Points=m;
}
void fslvtkIO::setPolygons(Matrix m){
Polygons=m;
}
void fslvtkIO::setVectors(Matrix m){
Vectors=m;
}
void fslvtkIO::setScalars(Matrix m){
Scalars=m;
}
void fslvtkIO::setDataType(string s){
DataType=s;
}
void fslvtkIO::addFieldData(Matrix M, string name, string type){
fieldDataNum.push_back(M);
fieldDataNumName.push_back(name);
fieldDataNumType.push_back(type);
}
void fslvtkIO::addFieldData(vector< string > str, string name){
fieldDataStr.push_back(str);
fieldDataStrName.push_back(name);
}
void fslvtkIO::save(string s){
ofstream fshape;
fshape.open(s.c_str());
#ifdef PPC64
int n=0;
#endif
//calculate total number of points
fshape<<"# vtk DataFile Version 3.0"<<endl<<"this file was written using fslvtkio"<<endl<<"ASCII"<<endl<<"DATASET ";
fshape<<DataType<<endl;
//only handle polydata currently
//writing points to vtk file
if (Points.Nrows()>0){
fshape<<"POINTS "<<Points.Nrows()<<" float"<<endl;
for (int i=0;i<Points.Nrows();i++){
//cols should always be three
fshape<<Points.element(i,0)<<" "<<Points.element(i,1)<<" "<<Points.element(i,2)<<endl;
}
#ifdef PPC64
if ((n++ % 20) == 0) fshape.flush();
#endif
}
if (Polygons.Nrows()>0){
fshape<<"POLYGONS "<<Polygons.Nrows()<<" "<<Polygons.Nrows()*(Polygons.Ncols()+1)<<endl;
for (int i=0;i<Polygons.Nrows();i++){
for (int j=0;j<Polygons.Ncols();j++){
if (j==0){
fshape<<Polygons.Ncols()<<" ";
}
if (j==(Polygons.Ncols()-1)){
fshape<<Polygons.element(i,j)<<endl;
}else{
fshape<<Polygons.element(i,j)<<" ";
}
}
#ifdef PPC64
if ((n++ % 20) == 0) fshape.flush();
#endif
}
}
//handle point data
if ( (Scalars.Nrows()>0) || (Vectors.Nrows()>0) ) {
fshape<<"POINT_DATA "<<Points.Nrows()<<endl;
if (Scalars.Nrows()>0){
fshape<<"SCALARS "<<scalarsName<<" float"<<endl;
fshape<<"LOOKUP_TABLE default"<<endl;
for (int i=0;i<Scalars.Nrows();i++){
for (int j=0;j<Scalars.Ncols();j++){
if (j==(Scalars.Ncols()-1)){
fshape<<Scalars.element(i,j)<<endl;
}else{
fshape<<Scalars.element(i,j)<<" ";
}
}
#ifdef PPC64
if ((n++ % 20) == 0) fshape.flush();
#endif
}
}
if (Vectors.Nrows()>0){
fshape<<"VECTORS "<<vectorsName<<" float"<<endl;
for (int i=0;i<Vectors.Nrows();i++){
for (int j=0;j<Vectors.Ncols();j++){
if (j==(Vectors.Ncols()-1)){
fshape<<Vectors.element(i,j)<<endl;
}else{
fshape<<Vectors.element(i,j)<<" ";
}
}
#ifdef PPC64
if ((n++ % 20) == 0) fshape.flush();
#endif
}
}
}
//Ignored cell data for now
//write field data
if ( ( fieldDataStr.size()>0) || (fieldDataNum.size()>0) ){
fshape<<"Field FieldData"<<" "<<fieldDataNum.size()+fieldDataStr.size()<<endl;
//write out numerixc field data
if (fieldDataNum.size()>0){
for (unsigned int i=0; i<fieldDataNum.size();i++){
Matrix mtemp=fieldDataNum.at(i);
fshape<<fieldDataNumName.at(i)<<" "<<mtemp.Nrows()<<" "<<mtemp.Ncols()<<" "<<fieldDataNumType.at(i)<<endl;
for (int j=0;j<mtemp.Nrows();j++){
for (int k=0;k<mtemp.Ncols();k++){
if (k==(mtemp.Ncols()-1)){
fshape<<mtemp.element(j,k)<<endl;
}else{
fshape<<mtemp.element(j,k)<<" ";
}
}
#ifdef PPC64
if ((n++ % 20) == 0) fshape.flush();
#endif
}
}
}
if (fieldDataStr.size()>0){
for (unsigned int i=0; i<fieldDataStr.size();i++){
vector<string> mtemp=fieldDataStr.at(i);
fshape<<fieldDataStrName.at(i)<<" "<<mtemp.size()<<" "<<1<<" "<<"string"<<endl;
for (unsigned int j=0;j<mtemp.size();j++){
//if (i==mtemp.size()){
fshape<<mtemp.at(j)<<endl;
//}else{
// fshape<<mtemp.at(j)<<" ";
// }
#ifdef PPC64
if ((n++ % 50) == 0) fshape.flush();
#endif
}
}
}
}
fshape.close();
}
void fslvtkio::readPolyData(string name, Mesh*, vector<Matrix>* pointData, vector<int>* pdID, vector<Matrix>* cellData, vector<int>* cdID, vector<Matrix>* fieldData,, vector<string>* fdName){
ifstream fvtk;
fvtk.open(s.c_str());
string stemp;
getline(fvtk,stemp);
getline(fvtk,stemp);//used to get rid of second ascii line to avoid "modes"
cout<<stemp<<endl;
fvtk>>stemp;
cout<<stemp<<endl;
fvtk>>stemp;
cout<<stemp<<endl;
}
}
#ifndef _fslvtkIO
#define _fslvtkIO
#include <iostream>
#include <string>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#include "meshclass/meshclass.h"
using namespace std;
using namespace mesh;
namespace fslvtkio{
class fslvtkIO {
public:
fslvtkIO();
~fslvtkIO();
void setDataType(string name);
void setPoints(Matrix pts);
void setPolygons(Matrix pts);
void setMesh(Mesh m);
void setScalars(Matrix sc,string name);
void setScalars(Matrix sc);
void setVectors(Matrix vecs,string name);
void setVectors(Matrix vecs);
void addFieldData(Matrix m,string name, string type);
void addFieldData(vector< string >,string name);
void readPolyData(string name, Mesh*, vector<Matrix>* pointData, vector<int>* pdID, vector<Matrix>* cellData, vector<int>* cdID, vector<Matrix>* fieldData,, vector<string>* fdName);
void save(string s);
private:
Matrix Scalars;
Matrix Vectors;
Matrix Points;
Matrix Polygons;
string DataType;//i.e. POLYDATA
string scalarsName, vectorsName;
vector< Matrix > fieldDataNum;
vector< string > fieldDataNumName;
vector< string > fieldDataNumType;
vector< vector<string> > fieldDataStr;
vector< string > fieldDataStrName;
};
}
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment