From 363fdbe6d98b538b4d416fa0bb21e5b566f00a76 Mon Sep 17 00:00:00 2001 From: Trevor Keller Date: Mon, 20 Aug 2018 19:19:40 -0400 Subject: [PATCH 1/8] VTK-dependent utility compiles and runs, with errors --- README.md | 1 + utility/Makefile | 8 +- utility/mmsp2vti.cpp | 1316 ++++++++++++++++++------------------------ 3 files changed, 556 insertions(+), 769 deletions(-) diff --git a/README.md b/README.md index df7e714..247c6c9 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ MMSP is nothing more than a collection of C++ header files that declare a number * An ISO compliant C++ compiler (e.g. GCC 2.95 or later) * zlib libraries for data compression (e.g. zlib 1.2.7) * libpng headers for mmsp2png image generation utility (e.g. libpng12-dev) + * libvtk headers for mmsp2vti image generation utility (e.g. libvtk6-dev) * MPI libraries if compiling parallel programs (e.g. Open MPI) *Documentation* diff --git a/utility/Makefile b/utility/Makefile index 50d1bff..5a81d3d 100644 --- a/utility/Makefile +++ b/utility/Makefile @@ -4,8 +4,8 @@ # compilers/flags compiler = g++ -flags = -O2 -Wall -pedantic -I ../include/ - +flags = -O2 -Wall -I ../include -I /usr/include/vtk-6.3 -L /usr/lib/x86_64-linux-gnu +vtklinks = -lvtkCommonCore-6.3 -lvtkCommonDataModel-6.3 -lvtkIOXML-6.3 topo = ../algorithms/topology # conversion programs @@ -36,6 +36,10 @@ mmsp2tsv : mmsp2tsv.cpp mmsp2vti : mmsp2vti.cpp $(compiler) $(flags) $< -o $@ -lz +# convert MMSP grid file to compressed VTK Image file type +mmsp2vtz : mmsp2vti.cpp + $(compiler) $(flags) -O0 -g $< -o $@ $(vtklinks) -lz + # convert MMSP grid file to XYZ point cloud file type mmsp2xyz : mmsp2xyz.cpp $(compiler) $(flags) $< -o $@ -lz diff --git a/utility/mmsp2vti.cpp b/utility/mmsp2vti.cpp index 5b7d336..2b98384 100644 --- a/utility/mmsp2vti.cpp +++ b/utility/mmsp2vti.cpp @@ -1,33 +1,47 @@ // mmsp2vti.cpp -// Convert MMSP grid data to VTK image data format +// Convert MMSP grid data to XML VTK image data format // Questions/comments to gruberja@gmail.com (Jason Gruber) -#include -#include -#include -#include -#include"MMSP.hpp" - - -template void print_scalars(std::ofstream& fstr, const MMSP::grid& GRID, const int& mode) +#include +#include +#include +#include +#include +#include +#include +#include +#include "MMSP.hpp" + +template void print_scalars(std::string filename, const MMSP::grid& GRID, const int mode) { + vtkSmartPointer imageData = vtkSmartPointer::New(); + imageData->SetDimensions(MMSP::xlength(GRID, 0), MMSP::xlength(GRID, 1), MMSP::xlength(GRID, 2)); + #if VTK_MAJOR_VERSION <= 5 + imageData->SetNumberOfScalarComponents(1); + imageData->SetScalarTypeToDouble(); + #else + imageData->AllocateScalars(VTK_DOUBLE, 1); + #endif + if (dim==1) { MMSP::vector x(1,0); for (x[0]=MMSP::x0(GRID); x[0](imageData->GetScalarPointer(x[0] - MMSP::x0(GRID), 0, 0)); if (mode==1) { // --mag - fstr << std::sqrt(GRID(x)*GRID(x)) << " "; + pixel[0] = std::sqrt(GRID(x)*GRID(x)); } else { - fstr << GRID(x) << " "; + pixel[0] = GRID(x); } } } else if (dim==2) { MMSP::vector x(2,0); for (x[1]=MMSP::y0(GRID); x[1](imageData->GetScalarPointer(x[0] - MMSP::x0(GRID), x[1] - MMSP::y0(GRID), 0)); if (mode==1) { // --mag - fstr << std::sqrt(GRID(x)*GRID(x)) << " "; + pixel[0] = std::sqrt(GRID(x)*GRID(x)); } else { - fstr << GRID(x) << " "; + pixel[0] = GRID(x); } } } @@ -36,119 +50,197 @@ template void print_scalars(std::ofstream& fstr, const MMSP for (x[2]=MMSP::z0(GRID); x[2](imageData->GetScalarPointer(x[0] - MMSP::x0(GRID), x[1] - MMSP::y0(GRID), x[2] - MMSP::z0(GRID))); if (mode==1) { // --mag - fstr << std::sqrt(GRID(x)*GRID(x)) << " "; + pixel[0] = std::sqrt(GRID(x)*GRID(x)); } else { - fstr << GRID(x) << " "; + pixel[0] = GRID(x); } } } } } + + vtkSmartPointer writer = vtkSmartPointer::New(); + writer->SetFileName(filename.c_str()); + // writer->SetCompressorType(ZLIB); + #if VTK_MAJOR_VERSION <= 5 + writer->SetInputConnection(imageData->GetProducerPort()); + #else + writer->SetInputData(imageData); + #endif + writer->Write(); } -template void print_vectors(std::ofstream& fstr, const MMSP::grid >& GRID, - const int& mode, const int& field) +template void print_vectors(std::string filename, const MMSP::grid >& GRID, + const int mode, const int field) { + vtkSmartPointer imageData = vtkSmartPointer::New(); + #if VTK_MAJOR_VERSION <= 5 + imageData->SetScalarTypeToDouble(); + #endif + if (dim==1) { + imageData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), 1, 1); + #if VTK_MAJOR_VERSION <= 5 + if (mode==1 || mode==2 || mode==3) + imageData->SetNumberOfScalarComponents(1); + else + imageData->SetNumberOfScalarComponents(MMSP::fields(GRID)); + #else + if (mode==1 || mode==2 || mode==3) + imageData->AllocateScalars(VTK_DOUBLE, 1); + else + imageData->AllocateScalars(VTK_DOUBLE, MMSP::fields(GRID)); + #endif + MMSP::vector x(1,0); for (x[0]=MMSP::x0(GRID); x[0]& v = GRID(x); + double* pixel = static_cast(imageData->GetScalarPointer(x[0] - MMSP::x0(GRID), 0, 0)); if (mode==1) { // --mag double sum = 0.0; for (int h = 0; h < v.length(); h++) sum += v[h]*v[h]; - fstr << std::sqrt(sum) << " "; + pixel[0] = std::sqrt(sum); } else if (mode==2) { // --max // Export index of field with greatest magnitude int max = 0; for (int h = 1; h < v.length(); h++) if (v[h] > v[max]) max = h; - fstr << max << " "; + pixel[0] = max; } else if (mode==3) { // --field - fstr << v[field] << " "; + pixel[0] = v[field]; } else { for (int h = 0; h < v.length(); h++) - fstr << v[h] << " "; + pixel[h] = v[h]; } } } else if (dim==2) { + imageData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), MMSP::y1(GRID)-MMSP::y0(GRID), 1); + #if VTK_MAJOR_VERSION <= 5 + if (mode==1 || mode==2 || mode==3) + imageData->SetNumberOfScalarComponents(1); + else + imageData->SetNumberOfScalarComponents(MMSP::fields(GRID)); + #else + if (mode==1 || mode==2 || mode==3) + imageData->AllocateScalars(VTK_DOUBLE, 1); + else + imageData->AllocateScalars(VTK_DOUBLE, MMSP::fields(GRID)); + #endif + MMSP::vector x(2,0); for (x[1]=MMSP::y0(GRID); x[1]& v = GRID(x); + double* pixel = static_cast(imageData->GetScalarPointer(x[0] - MMSP::x0(GRID), x[1] - MMSP::y0(GRID), 0)); if (mode==1) { // --mag double sum = 0.0; for (int h = 0; h < v.length(); h++) sum += v[h]*v[h]; - fstr << std::sqrt(sum) << " "; + pixel[0] = std::sqrt(sum); } else if (mode==2) { // --max // Export index of field with greatest magnitude int max = 0; for (int h = 1; h < v.length(); h++) if (v[h] > v[max]) max = h; - fstr << max << " "; + pixel[0] = max; } else if (mode==3) { // --field - fstr << v[field] << " "; + pixel[0] = v[field]; } else { for (int h = 0; h < v.length(); h++) - fstr << v[h] << " "; + pixel[h] = v[h]; } } } } else if (dim==3) { + imageData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), MMSP::y1(GRID)-MMSP::y0(GRID), MMSP::z1(GRID)-MMSP::z0(GRID)); + #if VTK_MAJOR_VERSION <= 5 + if (mode==1 || mode==2 || mode==3) + imageData->SetNumberOfScalarComponents(1); + else + imageData->SetNumberOfScalarComponents(MMSP::fields(GRID)); + #else + if (mode==1 || mode==2 || mode==3) + imageData->AllocateScalars(VTK_DOUBLE, 1); + else + imageData->AllocateScalars(VTK_DOUBLE, MMSP::fields(GRID)); + #endif + MMSP::vector x(3,0); for (x[2]=MMSP::z0(GRID); x[2]& v = GRID(x); + double* pixel = static_cast(imageData->GetScalarPointer(x[0] - MMSP::x0(GRID), x[1] - MMSP::y0(GRID), x[2] - MMSP::z0(GRID))); if (mode==1) { // --mag double sum = 0.0; for (int h = 0; h < v.length(); h++) sum += v[h]*v[h]; - fstr << std::sqrt(sum) << " "; + pixel[0] = std::sqrt(sum); } else if (mode==2) { // --max // Export index of field with greatest magnitude int max = 0; for (int h = 1; h < v.length(); h++) if (v[h] > v[max]) max = h; - fstr << max << " "; + pixel[0] = max; } else if (mode==3) { // --field - fstr << v[field] << " "; + pixel[0] = v[field]; } else { for (int h = 0; h < v.length(); h++) - fstr << v[h] << " "; + pixel[h] = v[h]; } } } } } + + vtkSmartPointer writer = vtkSmartPointer::New(); + writer->SetFileName(filename.c_str()); + // writer->SetCompressorType(ZLIB); + #if VTK_MAJOR_VERSION <= 5 + writer->SetInputConnection(imageData->GetProducerPort()); + #else + writer->SetInputData(imageData); + #endif + writer->Write(); } -template void print_sparses(std::ofstream& fstr, const MMSP::grid >& GRID, - const int& mode, const int& field) +template void print_sparses(std::string filename, const MMSP::grid >& GRID, + const int mode, const int field) { + vtkSmartPointer imageData = vtkSmartPointer::New(); + imageData->SetDimensions(MMSP::xlength(GRID, 0), MMSP::xlength(GRID, 1), MMSP::xlength(GRID, 2)); + #if VTK_MAJOR_VERSION <= 5 + imageData->SetNumberOfScalarComponents(1); + imageData->SetScalarTypeToDouble(); + #else + imageData->AllocateScalars(VTK_DOUBLE, 1); + #endif + if (dim==1) { MMSP::vector x(1,0); for (x[0]=MMSP::x0(GRID); x[0]& s = GRID(x); + double* pixel = static_cast(imageData->GetScalarPointer(x[0] - MMSP::x0(GRID), 0, 0)); if (mode==2) { // --max // Export index of field with greatest magnitude int max = 0; for (int h = 1; h < s.length(); h++) if (s.value(h) > s.value(max)) max = h; - fstr << s.index(max) << " "; + pixel[0] = s.index(max); } else if (mode==3) { // --field - fstr << s[field] << " "; + pixel[0] = s[field]; } else { // --mag is redundant for sparse double sum = 0.0; for (int h = 0; h < s.length(); h++) sum += s.value(h)*s.value(h); - fstr << std::sqrt(sum) << " "; + pixel[0] = std::sqrt(sum); } } } else if (dim==2) { @@ -156,20 +248,21 @@ template void print_sparses(std::ofstream& fstr, const MMSP for (x[1]=MMSP::y0(GRID); x[1]& s = GRID(x); + double* pixel = static_cast(imageData->GetScalarPointer(x[0] - MMSP::x0(GRID), x[1] - MMSP::y0(GRID), 0)); if (mode==2) { // --max // Export index of field with greatest magnitude int max = 0; for (int h = 1; h < s.length(); h++) if (s.value(h) > s.value(max)) max = h; - fstr << s.index(max) << " "; + pixel[0] = s.index(max); } else if (mode==3) { // --field - fstr << s[field] << " "; + pixel[0] = s[field]; } else { // --mag is redundant for sparse double sum = 0.0; for (int h = 0; h < s.length(); h++) sum += s.value(h)*s.value(h); - fstr << std::sqrt(sum) << " "; + pixel[0] = std::sqrt(sum); } } } @@ -179,25 +272,36 @@ template void print_sparses(std::ofstream& fstr, const MMSP for (x[1]=MMSP::y0(GRID); x[1]& s = GRID(x); + double* pixel = static_cast(imageData->GetScalarPointer(x[0] - MMSP::x0(GRID), x[1] - MMSP::y0(GRID), x[2] - MMSP::z0(GRID))); if (mode==2) { // --max // Export index of field with greatest magnitude int max = 0; for (int h = 1; h < s.length(); h++) if (s.value(h) > s.value(max)) max = h; - fstr << s.index(max) << " "; + pixel[0] = s.index(max); } else if (mode==3) { // --field - fstr << s[field] << " "; + pixel[0] = s[field]; } else { // --mag is redundant for sparse double sum = 0.0; for (int h = 0; h < s.length(); h++) sum += s.value(h)*s.value(h); - fstr << std::sqrt(sum) << " "; + pixel[0] = std::sqrt(sum); } } } } } + + vtkSmartPointer writer = vtkSmartPointer::New(); + writer->SetFileName(filename.c_str()); + // writer->SetCompressorType(ZLIB); + #if VTK_MAJOR_VERSION <= 5 + writer->SetInputConnection(imageData->GetProducerPort()); + #else + writer->SetInputData(imageData); + #endif + writer->Write(); } int main(int argc, char* argv[]) @@ -248,14 +352,6 @@ int main(int argc, char* argv[]) else filename << argv[fileindex+1]; - // file open error check - std::ofstream output(filename.str().c_str()); - if (!output) { - std::cerr << "File output error: could not open "; - std::cerr << filename.str() << "." << std::endl; - exit(-1); - } - // read data type std::string type; getline(input, type, '\n'); @@ -280,17 +376,16 @@ int main(int argc, char* argv[]) bool double_type = (type.find("double") != std::string::npos); bool long_double_type = (type.find("long double") != std::string::npos); - bool scalar_type = (type.find("scalar") != std::string::npos); bool vector_type = (type.find("vector") != std::string::npos); bool sparse_type = (type.find("sparse") != std::string::npos); if (not bool_type and - not char_type and not unsigned_char_type and - not int_type and not unsigned_int_type and - not long_type and not unsigned_long_type and - not short_type and not unsigned_short_type and - not float_type and - not double_type and not long_double_type) { + not char_type and not unsigned_char_type and + not int_type and not unsigned_int_type and + not long_type and not unsigned_long_type and + not short_type and not unsigned_short_type and + not float_type and + not double_type and not long_double_type) { std::cerr << "File input error: unknown grid data type." << std::endl; exit(-1); } @@ -303,726 +398,413 @@ int main(int argc, char* argv[]) exit(-1); } - // read number of fields - int fields; - input >> fields; - - // read grid sizes - int x0[3] = {0, 0, 0}; - int x1[3] = {0, 0, 0}; - for (int i = 0; i < dim; i++) - input >> x0[i] >> x1[i]; - - // read cell spacing - float dx[3] = {1.0, 1.0, 1.0}; - for (int i = 0; i < dim; i++) - input >> dx[i]; - - // ignore trailing endlines - input.ignore(10, '\n'); - - - // determine byte order: 01 AND 01 = 01; 01 AND 10 = 00. - std::string byte_order; - if (0x01 & static_cast(1)) byte_order = "LittleEndian"; - else byte_order = "BigEndian"; - - // output header markup - output << "\n"; - output << "\n"; - - if (dim == 1) { - output << " \n"; - } else if (dim == 2) { - output << " \n"; - } else if (dim == 3) { - output << " \n"; - } else { - std::cerr<<"Error: "<(&blocks), sizeof(blocks)); - - for (int i = 0; i < blocks; i++) { - // read block limits - int lmin[3] = {0, 0, 0}; - int lmax[3] = {0, 0, 0}; - for (int j = 0; j < dim; j++) { - input.read(reinterpret_cast(&lmin[j]), sizeof(lmin[j])); - input.read(reinterpret_cast(&lmax[j]), sizeof(lmax[j])); - } - int blo[3]; - int bhi[3]; - // read boundary conditions - for (int j = 0; j < dim; j++) { - input.read(reinterpret_cast(&blo[j]), sizeof(blo[j])); - input.read(reinterpret_cast(&bhi[j]), sizeof(bhi[j])); - } - - // write header markup - if (dim == 1) - output << " \n"; - if (dim == 2) - output << " \n"; - if (dim == 3) - output << " \n"; - - // write cell data markup - if (scalar_type || flatten>0) { - output << " \n"; - output << " \n"; - output << " \n"; - output << " \n"; - output << " \n"; - else if (flatten==2) // max - output << " type=\"Int32\" format=\"ascii\">\n"; - else if (bool_type) - output << " type=\"UInt8\" format=\"ascii\">\n"; - else if (char_type) - output << " type=\"Int8\" format=\"ascii\">\n"; - else if (unsigned_char_type) - output << " type=\"UInt8\" format=\"ascii\">\n"; - else if (int_type) - output << " type=\"Int32\" format=\"ascii\">\n"; - else if (unsigned_int_type) - output << " type=\"UInt32\" format=\"ascii\">\n"; - else if (long_type) - output << " type=\"Int32\" format=\"ascii\">\n"; - else if (unsigned_long_type) - output << " type=\"UInt32\" format=\"ascii\">\n"; - else if (short_type) - output << " type=\"Int16\" format=\"ascii\">\n"; - else if (unsigned_short_type) - output << " type=\"UInt16\" format=\"ascii\">\n"; - else if (float_type) - output << " type=\"Float32\" format=\"ascii\">\n"; - else if (double_type) - output << " type=\"Float64\" format=\"ascii\">\n"; - else if (long_double_type) - output << " type=\"Float128\" format=\"ascii\">\n"; - - - // read grid data - unsigned long size, rawSize; - input.read(reinterpret_cast(&rawSize), sizeof(rawSize)); // read raw size - input.read(reinterpret_cast(&size), sizeof(size)); // read compressed size - char* compressed_buffer = new char[size]; - input.read(compressed_buffer, size); - char* buffer = NULL; - if (size != rawSize) { - // Decompress data - buffer = new char[rawSize]; - int status; - status = uncompress(reinterpret_cast(buffer), &rawSize, reinterpret_cast(compressed_buffer), size); - switch(status) { - case Z_OK: - break; - case Z_MEM_ERROR: - std::cerr << "Uncompress: out of memory." << std::endl; - exit(1); - break; - case Z_BUF_ERROR: - std::cerr << "Uncompress: output buffer wasn't large enough." << std::endl; - exit(1); - break; - } - delete [] compressed_buffer; - compressed_buffer = NULL; - } else { - buffer = compressed_buffer; - compressed_buffer = NULL; - } - - // write grid data - if (not vector_type and not sparse_type) { // must be scalar or built-in - if (bool_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 2) { - MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 3) { - MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } - } - else if (unsigned_char_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 2) { - MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 3) { - MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } - } - else if (char_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 2) { - MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 3) { - MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } - } - else if (unsigned_int_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 2) { - MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 3) { - MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } - } - else if (int_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 2) { - MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 3) { - MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } - } - else if (unsigned_long_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 2) { - MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 3) { - MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } - } - else if (long_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 2) { - MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 3) { - MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } - } - else if (unsigned_short_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 2) { - MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 3) { - MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } - } - else if (short_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 2) { - MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 3) { - MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } - } - else if (float_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 2) { - MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 3) { - MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } - } - else if (long_double_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 2) { - MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 3) { - MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } - } - else if (double_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 2) { - MMSP::grid<2, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } else if (dim == 3) { - MMSP::grid<3, MMSP::scalar > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_scalars(output, GRID, flatten); - } + // write grid data + if (not vector_type and not sparse_type) { // must be scalar or built-in + if (bool_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); + } else if (dim == 2) { + MMSP::grid<2, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); + } else if (dim == 3) { + MMSP::grid<3, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); + } + } else if (unsigned_char_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); + } else if (dim == 2) { + MMSP::grid<2, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); + } else if (dim == 3) { + MMSP::grid<3, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); + } + } else if (char_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); + } else if (dim == 2) { + MMSP::grid<2, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); + } else if (dim == 3) { + MMSP::grid<3, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); + } + } else if (unsigned_int_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); + } else if (dim == 2) { + MMSP::grid<2, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); + } else if (dim == 3) { + MMSP::grid<3, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); + } + } else if (int_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); + } else if (dim == 2) { + MMSP::grid<2, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); + } else if (dim == 3) { + MMSP::grid<3, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); + } + } else if (unsigned_long_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); + } else if (dim == 2) { + MMSP::grid<2, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); + } else if (dim == 3) { + MMSP::grid<3, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); + } + } else if (long_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); + } else if (dim == 2) { + MMSP::grid<2, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); + } else if (dim == 3) { + MMSP::grid<3, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); + } + } else if (unsigned_short_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); + } else if (dim == 2) { + MMSP::grid<2, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); + } else if (dim == 3) { + MMSP::grid<3, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); + } + } else if (short_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); + } else if (dim == 2) { + MMSP::grid<2, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); + } else if (dim == 3) { + MMSP::grid<3, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); + } + } else if (float_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); + } else if (dim == 2) { + MMSP::grid<2, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); + } else if (dim == 3) { + MMSP::grid<3, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); + } + } else if (long_double_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); + } else if (dim == 2) { + MMSP::grid<2, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); + } else if (dim == 3) { + MMSP::grid<3, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); + } + } else if (double_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); + } else if (dim == 2) { + MMSP::grid<2, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); + } else if (dim == 3) { + MMSP::grid<3, MMSP::scalar > GRID(argv[fileindex]); + print_scalars(filename.str(), GRID, flatten); } } + } - else if (vector_type) { - if (bool_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } - } - else if (unsigned_char_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } - } - else if (char_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } - } - else if (unsigned_int_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } - } - else if (int_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } - } - else if (unsigned_long_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } - } - else if (long_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } - } - else if (unsigned_short_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } - } - else if (short_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } - } - else if (float_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } - } - else if (long_double_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } - } - else if (double_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::vector > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_vectors(output, GRID, flatten, field); - } + else if (vector_type) { + if (bool_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); + } + } else if (unsigned_char_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); + } + } else if (char_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); + } + } else if (unsigned_int_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); + } + } else if (int_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); + } + } else if (unsigned_long_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); + } + } else if (long_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); + } + } else if (unsigned_short_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); + } + } else if (short_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); + } + } else if (float_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); + } + } else if (long_double_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); + } + } else if (double_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::vector > GRID(argv[fileindex]); + print_vectors(filename.str(), GRID, flatten, field); } } + } - else if (sparse_type) { - if (bool_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } - } - else if (unsigned_char_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } - } - else if (char_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } - } - else if (unsigned_int_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } - } - else if (int_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } - } - else if (unsigned_long_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } - } - else if (long_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } - } - else if (unsigned_short_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } - } - else if (short_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } - } - else if (float_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } - } - else if (long_double_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } - } - else if (double_type) { - if (dim == 1) { - MMSP::grid<1, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 2) { - MMSP::grid<2, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } else if (dim == 3) { - MMSP::grid<3, MMSP::sparse > GRID(fields, lmin, lmax); - GRID.from_buffer(buffer); - print_sparses(output, GRID, flatten, field); - } + else if (sparse_type) { + if (bool_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); + } + } else if (unsigned_char_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); + } + } else if (char_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); + } + } else if (unsigned_int_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); + } + } else if (int_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); + } + } else if (unsigned_long_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); + } + } else if (long_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); + } + } else if (unsigned_short_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); + } + } else if (short_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); + } + } else if (float_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); + } + } else if (long_double_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); + } + } else if (double_type) { + if (dim == 1) { + MMSP::grid<1, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); + } else if (dim == 2) { + MMSP::grid<2, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); + } else if (dim == 3) { + MMSP::grid<3, MMSP::sparse > GRID(argv[fileindex]); + print_sparses(filename.str(), GRID, flatten, field); } } - - // clean up - delete [] buffer; - - // write closing markup - output << "\n"; - output << " \n"; - output << " \n"; - output << " \n"; } -// output closing markup - output << " \n"; - output << "\n"; } From 54191f5e3071a0059153b6f39ae485c75c7dfcd8 Mon Sep 17 00:00:00 2001 From: Trevor Keller Date: Tue, 21 Aug 2018 17:56:59 -0400 Subject: [PATCH 2/8] VTK utility runs, output larger than expected, only implemented for vectors --- utility/Makefile | 2 +- utility/mmsp2vti.cpp | 115 +++++++++++++++++++++++++------------------ 2 files changed, 68 insertions(+), 49 deletions(-) diff --git a/utility/Makefile b/utility/Makefile index 5a81d3d..8b0b47c 100644 --- a/utility/Makefile +++ b/utility/Makefile @@ -38,7 +38,7 @@ mmsp2vti : mmsp2vti.cpp # convert MMSP grid file to compressed VTK Image file type mmsp2vtz : mmsp2vti.cpp - $(compiler) $(flags) -O0 -g $< -o $@ $(vtklinks) -lz + $(compiler) $(flags) $< -o $@ $(vtklinks) -lz # convert MMSP grid file to XYZ point cloud file type mmsp2xyz : mmsp2xyz.cpp diff --git a/utility/mmsp2vti.cpp b/utility/mmsp2vti.cpp index 2b98384..9d72a7d 100644 --- a/utility/mmsp2vti.cpp +++ b/utility/mmsp2vti.cpp @@ -5,28 +5,31 @@ #include #include #include -#include -#include +#include +#include +#include #include +#include +#include #include -#include +#include #include "MMSP.hpp" template void print_scalars(std::string filename, const MMSP::grid& GRID, const int mode) { - vtkSmartPointer imageData = vtkSmartPointer::New(); - imageData->SetDimensions(MMSP::xlength(GRID, 0), MMSP::xlength(GRID, 1), MMSP::xlength(GRID, 2)); + vtkSmartPointer vtkData = vtkSmartPointer::New(); + vtkData->SetDimensions(MMSP::xlength(GRID, 0), MMSP::xlength(GRID, 1), MMSP::xlength(GRID, 2)); #if VTK_MAJOR_VERSION <= 5 - imageData->SetNumberOfScalarComponents(1); - imageData->SetScalarTypeToDouble(); + vtkData->SetNumberOfScalarComponents(1); + vtkData->SetScalarTypeToDouble(); #else - imageData->AllocateScalars(VTK_DOUBLE, 1); + vtkData->AllocateScalars(VTK_DOUBLE, 1); #endif if (dim==1) { MMSP::vector x(1,0); for (x[0]=MMSP::x0(GRID); x[0](imageData->GetScalarPointer(x[0] - MMSP::x0(GRID), 0, 0)); + double* pixel = static_cast(vtkData->GetScalarPointer(x[0], 0, 0)); if (mode==1) { // --mag pixel[0] = std::sqrt(GRID(x)*GRID(x)); } else { @@ -37,7 +40,7 @@ template void print_scalars(std::string filename, const MMS MMSP::vector x(2,0); for (x[1]=MMSP::y0(GRID); x[1](imageData->GetScalarPointer(x[0] - MMSP::x0(GRID), x[1] - MMSP::y0(GRID), 0)); + double* pixel = static_cast(vtkData->GetScalarPointer(x[0], x[1], 0)); if (mode==1) { // --mag pixel[0] = std::sqrt(GRID(x)*GRID(x)); } else { @@ -50,7 +53,7 @@ template void print_scalars(std::string filename, const MMS for (x[2]=MMSP::z0(GRID); x[2](imageData->GetScalarPointer(x[0] - MMSP::x0(GRID), x[1] - MMSP::y0(GRID), x[2] - MMSP::z0(GRID))); + double* pixel = static_cast(vtkData->GetScalarPointer(x[0], x[1], x[2])); if (mode==1) { // --mag pixel[0] = std::sqrt(GRID(x)*GRID(x)); } else { @@ -63,41 +66,46 @@ template void print_scalars(std::string filename, const MMS vtkSmartPointer writer = vtkSmartPointer::New(); writer->SetFileName(filename.c_str()); - // writer->SetCompressorType(ZLIB); + writer->SetCompressorTypeToZLib(); #if VTK_MAJOR_VERSION <= 5 - writer->SetInputConnection(imageData->GetProducerPort()); + writer->SetInputConnection(vtkData->GetProducerPort()); #else - writer->SetInputData(imageData); + writer->SetInputData(vtkData); #endif writer->Write(); + + vtkData = NULL; + writer = NULL; } template void print_vectors(std::string filename, const MMSP::grid >& GRID, const int mode, const int field) { - vtkSmartPointer imageData = vtkSmartPointer::New(); + vtkSmartPointer vtkData = vtkSmartPointer::New(); #if VTK_MAJOR_VERSION <= 5 - imageData->SetScalarTypeToDouble(); + vtkData->SetScalarTypeToDouble(); #endif if (dim==1) { - imageData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), 1, 1); + vtkData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), 1, 1); + vtkData->SetExtent(MMSP::x0(GRID), MMSP::x1(GRID) - 1, 0, 0, 0, 0); + vtkData->SetSpacing(MMSP::dx(GRID), 1, 1); #if VTK_MAJOR_VERSION <= 5 if (mode==1 || mode==2 || mode==3) - imageData->SetNumberOfScalarComponents(1); + vtkData->SetNumberOfScalarComponents(1); else - imageData->SetNumberOfScalarComponents(MMSP::fields(GRID)); + vtkData->SetNumberOfScalarComponents(MMSP::fields(GRID)); #else if (mode==1 || mode==2 || mode==3) - imageData->AllocateScalars(VTK_DOUBLE, 1); + vtkData->AllocateScalars(VTK_DOUBLE, 1); else - imageData->AllocateScalars(VTK_DOUBLE, MMSP::fields(GRID)); + vtkData->AllocateScalars(VTK_DOUBLE, MMSP::fields(GRID)); #endif MMSP::vector x(1,0); for (x[0]=MMSP::x0(GRID); x[0]& v = GRID(x); - double* pixel = static_cast(imageData->GetScalarPointer(x[0] - MMSP::x0(GRID), 0, 0)); + double* pixel = static_cast(vtkData->GetScalarPointer(x[0], 0, 0)); if (mode==1) { // --mag double sum = 0.0; for (int h = 0; h < v.length(); h++) @@ -118,24 +126,26 @@ template void print_vectors(std::string filename, const MMS } } } else if (dim==2) { - imageData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), MMSP::y1(GRID)-MMSP::y0(GRID), 1); + vtkData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), MMSP::y1(GRID)-MMSP::y0(GRID), 1); + vtkData->SetExtent(MMSP::x0(GRID), MMSP::x1(GRID) - 1, MMSP::y0(GRID), MMSP::y1(GRID) - 1, 0, 0); + vtkData->SetSpacing(MMSP::dx(GRID, 0), MMSP::dx(GRID, 1), 1); #if VTK_MAJOR_VERSION <= 5 if (mode==1 || mode==2 || mode==3) - imageData->SetNumberOfScalarComponents(1); + vtkData->SetNumberOfScalarComponents(1); else - imageData->SetNumberOfScalarComponents(MMSP::fields(GRID)); + vtkData->SetNumberOfScalarComponents(MMSP::fields(GRID)); #else if (mode==1 || mode==2 || mode==3) - imageData->AllocateScalars(VTK_DOUBLE, 1); + vtkData->AllocateScalars(VTK_DOUBLE, 1); else - imageData->AllocateScalars(VTK_DOUBLE, MMSP::fields(GRID)); + vtkData->AllocateScalars(VTK_DOUBLE, MMSP::fields(GRID)); #endif MMSP::vector x(2,0); for (x[1]=MMSP::y0(GRID); x[1]& v = GRID(x); - double* pixel = static_cast(imageData->GetScalarPointer(x[0] - MMSP::x0(GRID), x[1] - MMSP::y0(GRID), 0)); + double* pixel = static_cast(vtkData->GetScalarPointer(x[0], x[1], 0)); if (mode==1) { // --mag double sum = 0.0; for (int h = 0; h < v.length(); h++) @@ -157,17 +167,19 @@ template void print_vectors(std::string filename, const MMS } } } else if (dim==3) { - imageData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), MMSP::y1(GRID)-MMSP::y0(GRID), MMSP::z1(GRID)-MMSP::z0(GRID)); + vtkData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), MMSP::y1(GRID)-MMSP::y0(GRID), MMSP::z1(GRID)-MMSP::z0(GRID)); + vtkData->SetExtent(MMSP::x0(GRID), MMSP::x1(GRID) - 1, MMSP::y0(GRID), MMSP::y1(GRID) - 1, MMSP::z0(GRID), MMSP::z1(GRID) - 1); + vtkData->SetSpacing(MMSP::dx(GRID, 0), MMSP::dx(GRID, 1), MMSP::dx(GRID, 2)); #if VTK_MAJOR_VERSION <= 5 if (mode==1 || mode==2 || mode==3) - imageData->SetNumberOfScalarComponents(1); + vtkData->SetNumberOfScalarComponents(1); else - imageData->SetNumberOfScalarComponents(MMSP::fields(GRID)); + vtkData->SetNumberOfScalarComponents(MMSP::fields(GRID)); #else if (mode==1 || mode==2 || mode==3) - imageData->AllocateScalars(VTK_DOUBLE, 1); + vtkData->AllocateScalars(VTK_DOUBLE, 1); else - imageData->AllocateScalars(VTK_DOUBLE, MMSP::fields(GRID)); + vtkData->AllocateScalars(VTK_DOUBLE, MMSP::fields(GRID)); #endif MMSP::vector x(3,0); @@ -175,7 +187,7 @@ template void print_vectors(std::string filename, const MMS for (x[1]=MMSP::y0(GRID); x[1]& v = GRID(x); - double* pixel = static_cast(imageData->GetScalarPointer(x[0] - MMSP::x0(GRID), x[1] - MMSP::y0(GRID), x[2] - MMSP::z0(GRID))); + double* pixel = static_cast(vtkData->GetScalarPointer(x[0], x[1], x[2])); if (mode==1) { // --mag double sum = 0.0; for (int h = 0; h < v.length(); h++) @@ -198,35 +210,39 @@ template void print_vectors(std::string filename, const MMS } } } + vtkData->GetPointData()->GetAbstractArray(0)->SetName("vector_data"); vtkSmartPointer writer = vtkSmartPointer::New(); writer->SetFileName(filename.c_str()); - // writer->SetCompressorType(ZLIB); + writer->SetCompressorTypeToZLib(); #if VTK_MAJOR_VERSION <= 5 - writer->SetInputConnection(imageData->GetProducerPort()); + writer->SetInputConnection(vtkData->GetProducerPort()); #else - writer->SetInputData(imageData); + writer->SetInputData(vtkData); #endif writer->Write(); + + vtkData = NULL; + writer = NULL; } template void print_sparses(std::string filename, const MMSP::grid >& GRID, const int mode, const int field) { - vtkSmartPointer imageData = vtkSmartPointer::New(); - imageData->SetDimensions(MMSP::xlength(GRID, 0), MMSP::xlength(GRID, 1), MMSP::xlength(GRID, 2)); + vtkSmartPointer vtkData = vtkSmartPointer::New(); + vtkData->SetDimensions(MMSP::xlength(GRID, 0), MMSP::xlength(GRID, 1), MMSP::xlength(GRID, 2)); #if VTK_MAJOR_VERSION <= 5 - imageData->SetNumberOfScalarComponents(1); - imageData->SetScalarTypeToDouble(); + vtkData->SetNumberOfScalarComponents(1); + vtkData->SetScalarTypeToDouble(); #else - imageData->AllocateScalars(VTK_DOUBLE, 1); + vtkData->AllocateScalars(VTK_DOUBLE, 1); #endif if (dim==1) { MMSP::vector x(1,0); for (x[0]=MMSP::x0(GRID); x[0]& s = GRID(x); - double* pixel = static_cast(imageData->GetScalarPointer(x[0] - MMSP::x0(GRID), 0, 0)); + double* pixel = static_cast(vtkData->GetScalarPointer(x[0], 0, 0)); if (mode==2) { // --max // Export index of field with greatest magnitude int max = 0; @@ -248,7 +264,7 @@ template void print_sparses(std::string filename, const MMS for (x[1]=MMSP::y0(GRID); x[1]& s = GRID(x); - double* pixel = static_cast(imageData->GetScalarPointer(x[0] - MMSP::x0(GRID), x[1] - MMSP::y0(GRID), 0)); + double* pixel = static_cast(vtkData->GetScalarPointer(x[0], x[1], 0)); if (mode==2) { // --max // Export index of field with greatest magnitude int max = 0; @@ -272,7 +288,7 @@ template void print_sparses(std::string filename, const MMS for (x[1]=MMSP::y0(GRID); x[1]& s = GRID(x); - double* pixel = static_cast(imageData->GetScalarPointer(x[0] - MMSP::x0(GRID), x[1] - MMSP::y0(GRID), x[2] - MMSP::z0(GRID))); + double* pixel = static_cast(vtkData->GetScalarPointer(x[0], x[1], x[2])); if (mode==2) { // --max // Export index of field with greatest magnitude int max = 0; @@ -295,13 +311,16 @@ template void print_sparses(std::string filename, const MMS vtkSmartPointer writer = vtkSmartPointer::New(); writer->SetFileName(filename.c_str()); - // writer->SetCompressorType(ZLIB); + writer->SetCompressorTypeToZLib(); #if VTK_MAJOR_VERSION <= 5 - writer->SetInputConnection(imageData->GetProducerPort()); + writer->SetInputConnection(vtkData->GetProducerPort()); #else - writer->SetInputData(imageData); + writer->SetInputData(vtkData); #endif writer->Write(); + + vtkData = NULL; + writer = NULL; } int main(int argc, char* argv[]) From db00e0050cc6409981decc80fe07681858e158ca Mon Sep 17 00:00:00 2001 From: Trevor Keller Date: Wed, 22 Aug 2018 00:46:03 -0400 Subject: [PATCH 3/8] functional, tested vector and sparse VTK writers --- utility/Makefile | 4 +- utility/mmsp2vti.cpp | 123 +++++++++++++++++++++++++++++++++---------- 2 files changed, 97 insertions(+), 30 deletions(-) diff --git a/utility/Makefile b/utility/Makefile index 8b0b47c..a387efa 100644 --- a/utility/Makefile +++ b/utility/Makefile @@ -4,8 +4,8 @@ # compilers/flags compiler = g++ -flags = -O2 -Wall -I ../include -I /usr/include/vtk-6.3 -L /usr/lib/x86_64-linux-gnu -vtklinks = -lvtkCommonCore-6.3 -lvtkCommonDataModel-6.3 -lvtkIOXML-6.3 +flags = -O2 -Wall -I ../include -I /usr/include/vtk -L /usr/lib/x86_64-linux-gnu +vtklinks = -lvtkCommonCore -lvtkCommonDataModel -lvtkIOXML topo = ../algorithms/topology # conversion programs diff --git a/utility/mmsp2vti.cpp b/utility/mmsp2vti.cpp index 9d72a7d..84b3b1e 100644 --- a/utility/mmsp2vti.cpp +++ b/utility/mmsp2vti.cpp @@ -6,27 +6,27 @@ #include #include #include -#include #include -#include #include #include #include -#include #include "MMSP.hpp" template void print_scalars(std::string filename, const MMSP::grid& GRID, const int mode) { vtkSmartPointer vtkData = vtkSmartPointer::New(); - vtkData->SetDimensions(MMSP::xlength(GRID, 0), MMSP::xlength(GRID, 1), MMSP::xlength(GRID, 2)); - #if VTK_MAJOR_VERSION <= 5 - vtkData->SetNumberOfScalarComponents(1); - vtkData->SetScalarTypeToDouble(); - #else - vtkData->AllocateScalars(VTK_DOUBLE, 1); - #endif if (dim==1) { + vtkData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), 1, 1); + vtkData->SetExtent(MMSP::x0(GRID), MMSP::x1(GRID) - 1, 0, 0, 0, 0); + vtkData->SetSpacing(MMSP::dx(GRID), 1, 1); + #if VTK_MAJOR_VERSION <= 5 + vtkData->SetScalarTypeToDouble(); + vtkData->SetNumberOfScalarComponents(1); + #else + vtkData->AllocateScalars(VTK_DOUBLE, 1); + #endif + MMSP::vector x(1,0); for (x[0]=MMSP::x0(GRID); x[0](vtkData->GetScalarPointer(x[0], 0, 0)); @@ -37,6 +37,20 @@ template void print_scalars(std::string filename, const MMS } } } else if (dim==2) { + vtkData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), + MMSP::y1(GRID)-MMSP::y0(GRID), + 1); + vtkData->SetExtent(MMSP::x0(GRID), MMSP::x1(GRID) - 1, + MMSP::y0(GRID), MMSP::y1(GRID) - 1, + 0, 0); + vtkData->SetSpacing(MMSP::dx(GRID, 0), MMSP::dx(GRID, 1), 1); + #if VTK_MAJOR_VERSION <= 5 + vtkData->SetScalarTypeToDouble(); + vtkData->SetNumberOfScalarComponents(1); + #else + vtkData->AllocateScalars(VTK_DOUBLE, 1); + #endif + MMSP::vector x(2,0); for (x[1]=MMSP::y0(GRID); x[1] void print_scalars(std::string filename, const MMS } } } else if (dim==3) { + vtkData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), + MMSP::y1(GRID)-MMSP::y0(GRID), + MMSP::z1(GRID)-MMSP::z0(GRID)); + vtkData->SetExtent(MMSP::x0(GRID), MMSP::x1(GRID) - 1, + MMSP::y0(GRID), MMSP::y1(GRID) - 1, + MMSP::z0(GRID), MMSP::z1(GRID) - 1); + vtkData->SetSpacing(MMSP::dx(GRID, 0), MMSP::dx(GRID, 1), MMSP::dx(GRID, 2)); + #if VTK_MAJOR_VERSION <= 5 + vtkData->SetScalarTypeToDouble(); + vtkData->SetNumberOfScalarComponents(1); + #else + vtkData->AllocateScalars(VTK_DOUBLE, 1); + #endif + MMSP::vector x(3,0); for (x[2]=MMSP::z0(GRID); x[2] void print_scalars(std::string filename, const MMS } } } + vtkData->GetPointData()->GetAbstractArray(0)->SetName("scalar_data"); vtkSmartPointer writer = vtkSmartPointer::New(); writer->SetFileName(filename.c_str()); - writer->SetCompressorTypeToZLib(); #if VTK_MAJOR_VERSION <= 5 writer->SetInputConnection(vtkData->GetProducerPort()); #else @@ -82,15 +110,13 @@ template void print_vectors(std::string filename, const MMS const int mode, const int field) { vtkSmartPointer vtkData = vtkSmartPointer::New(); - #if VTK_MAJOR_VERSION <= 5 - vtkData->SetScalarTypeToDouble(); - #endif if (dim==1) { vtkData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), 1, 1); - vtkData->SetExtent(MMSP::x0(GRID), MMSP::x1(GRID) - 1, 0, 0, 0, 0); + vtkData->SetExtent(MMSP::x0(GRID), MMSP::x1(GRID) - 1, 0, 0, 0, 0); vtkData->SetSpacing(MMSP::dx(GRID), 1, 1); #if VTK_MAJOR_VERSION <= 5 + vtkData->SetScalarTypeToDouble(); if (mode==1 || mode==2 || mode==3) vtkData->SetNumberOfScalarComponents(1); else @@ -126,10 +152,15 @@ template void print_vectors(std::string filename, const MMS } } } else if (dim==2) { - vtkData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), MMSP::y1(GRID)-MMSP::y0(GRID), 1); - vtkData->SetExtent(MMSP::x0(GRID), MMSP::x1(GRID) - 1, MMSP::y0(GRID), MMSP::y1(GRID) - 1, 0, 0); + vtkData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), + MMSP::y1(GRID)-MMSP::y0(GRID), + 1); + vtkData->SetExtent(MMSP::x0(GRID), MMSP::x1(GRID) - 1, + MMSP::y0(GRID), MMSP::y1(GRID) - 1, + 0, 0); vtkData->SetSpacing(MMSP::dx(GRID, 0), MMSP::dx(GRID, 1), 1); #if VTK_MAJOR_VERSION <= 5 + vtkData->SetScalarTypeToDouble(); if (mode==1 || mode==2 || mode==3) vtkData->SetNumberOfScalarComponents(1); else @@ -167,10 +198,15 @@ template void print_vectors(std::string filename, const MMS } } } else if (dim==3) { - vtkData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), MMSP::y1(GRID)-MMSP::y0(GRID), MMSP::z1(GRID)-MMSP::z0(GRID)); - vtkData->SetExtent(MMSP::x0(GRID), MMSP::x1(GRID) - 1, MMSP::y0(GRID), MMSP::y1(GRID) - 1, MMSP::z0(GRID), MMSP::z1(GRID) - 1); + vtkData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), + MMSP::y1(GRID)-MMSP::y0(GRID), + MMSP::z1(GRID)-MMSP::z0(GRID)); + vtkData->SetExtent(MMSP::x0(GRID), MMSP::x1(GRID) - 1, + MMSP::y0(GRID), MMSP::y1(GRID) - 1, + MMSP::z0(GRID), MMSP::z1(GRID) - 1); vtkData->SetSpacing(MMSP::dx(GRID, 0), MMSP::dx(GRID, 1), MMSP::dx(GRID, 2)); #if VTK_MAJOR_VERSION <= 5 + vtkData->SetScalarTypeToDouble(); if (mode==1 || mode==2 || mode==3) vtkData->SetNumberOfScalarComponents(1); else @@ -214,12 +250,12 @@ template void print_vectors(std::string filename, const MMS vtkSmartPointer writer = vtkSmartPointer::New(); writer->SetFileName(filename.c_str()); - writer->SetCompressorTypeToZLib(); #if VTK_MAJOR_VERSION <= 5 writer->SetInputConnection(vtkData->GetProducerPort()); #else writer->SetInputData(vtkData); #endif + writer->Write(); vtkData = NULL; @@ -230,15 +266,18 @@ template void print_sparses(std::string filename, const MMS const int mode, const int field) { vtkSmartPointer vtkData = vtkSmartPointer::New(); - vtkData->SetDimensions(MMSP::xlength(GRID, 0), MMSP::xlength(GRID, 1), MMSP::xlength(GRID, 2)); - #if VTK_MAJOR_VERSION <= 5 - vtkData->SetNumberOfScalarComponents(1); - vtkData->SetScalarTypeToDouble(); - #else - vtkData->AllocateScalars(VTK_DOUBLE, 1); - #endif if (dim==1) { + vtkData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), 1, 1); + vtkData->SetExtent(MMSP::x0(GRID), MMSP::x1(GRID) - 1, 0, 0, 0, 0); + vtkData->SetSpacing(MMSP::dx(GRID, 0), 1, 1); + #if VTK_MAJOR_VERSION <= 5 + vtkData->SetNumberOfScalarComponents(1); + vtkData->SetScalarTypeToDouble(); + #else + vtkData->AllocateScalars(VTK_DOUBLE, 1); + #endif + MMSP::vector x(1,0); for (x[0]=MMSP::x0(GRID); x[0]& s = GRID(x); @@ -260,6 +299,20 @@ template void print_sparses(std::string filename, const MMS } } } else if (dim==2) { + vtkData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), + MMSP::y1(GRID)-MMSP::y0(GRID), + 1); + vtkData->SetExtent(MMSP::x0(GRID), MMSP::x1(GRID) - 1, + MMSP::y0(GRID), MMSP::y1(GRID) - 1, + 0, 0); + vtkData->SetSpacing(MMSP::dx(GRID, 0), MMSP::dx(GRID, 1), 1); + #if VTK_MAJOR_VERSION <= 5 + vtkData->SetNumberOfScalarComponents(1); + vtkData->SetScalarTypeToDouble(); + #else + vtkData->AllocateScalars(VTK_DOUBLE, 1); + #endif + MMSP::vector x(2,0); for (x[1]=MMSP::y0(GRID); x[1] void print_sparses(std::string filename, const MMS } } } else if (dim==3) { + vtkData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), + MMSP::y1(GRID)-MMSP::y0(GRID), + MMSP::z1(GRID)-MMSP::z0(GRID)); + vtkData->SetExtent(MMSP::x0(GRID), MMSP::x1(GRID) - 1, + MMSP::y0(GRID), MMSP::y1(GRID) - 1, + MMSP::z0(GRID), MMSP::z1(GRID) - 1); + vtkData->SetSpacing(MMSP::dx(GRID, 0), MMSP::dx(GRID, 1), MMSP::dx(GRID, 2)); + #if VTK_MAJOR_VERSION <= 5 + vtkData->SetNumberOfScalarComponents(1); + vtkData->SetScalarTypeToDouble(); + #else + vtkData->AllocateScalars(VTK_DOUBLE, 1); + #endif + MMSP::vector x(3,0); for (x[2]=MMSP::z0(GRID); x[2] void print_sparses(std::string filename, const MMS } } } + vtkData->GetPointData()->GetAbstractArray(0)->SetName("sparse_data"); vtkSmartPointer writer = vtkSmartPointer::New(); writer->SetFileName(filename.c_str()); - writer->SetCompressorTypeToZLib(); #if VTK_MAJOR_VERSION <= 5 writer->SetInputConnection(vtkData->GetProducerPort()); #else From 2dc871accf5401797853f7cf085d9c24b092cbcf Mon Sep 17 00:00:00 2001 From: Trevor Keller Date: Wed, 22 Aug 2018 11:26:23 -0400 Subject: [PATCH 4/8] search for VTK, rather than hard-coding paths --- utility/Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/utility/Makefile b/utility/Makefile index a387efa..06b4427 100644 --- a/utility/Makefile +++ b/utility/Makefile @@ -2,9 +2,13 @@ # GNU makefile for grid conversion programs using MMSP # Questions/comments to gruberja@gmail.com (Jason Gruber) +# VTK path +VTK_SRC = $(shell dirname $(shell locate --limit 1 vtkImageData.h)) +VTK_LIB = $(shell dirname $(shell locate --limit 1 vtkCommonCore.so)) + # compilers/flags compiler = g++ -flags = -O2 -Wall -I ../include -I /usr/include/vtk -L /usr/lib/x86_64-linux-gnu +flags = -O2 -Wall -I ../include -I $(VTK_SRC) -L $(VTK_LIB) vtklinks = -lvtkCommonCore -lvtkCommonDataModel -lvtkIOXML topo = ../algorithms/topology From 2ce5fb36cfe968bcddebfb0a0176bffa5217e79a Mon Sep 17 00:00:00 2001 From: Trevor Keller Date: Wed, 22 Aug 2018 12:51:30 -0400 Subject: [PATCH 5/8] enable reading built-in grids, working VTK conversion --- include/MMSP.grid.cpp | 8 +- utility/Makefile | 11 ++- utility/mmsp2vti.cpp | 216 +++++++++++++++++++++--------------------- 3 files changed, 123 insertions(+), 112 deletions(-) diff --git a/include/MMSP.grid.cpp b/include/MMSP.grid.cpp index 65a95cc..94debbb 100644 --- a/include/MMSP.grid.cpp +++ b/include/MMSP.grid.cpp @@ -1181,10 +1181,14 @@ template void grid::input(const char* filename, int } // grid data type error check - std::string type; + std::string type, scalar_type; getline(input, type, '\n'); + scalar_type = "grid:scalar" + type.substr(type.find_last_of(":", 8)); + if (type != name(*this) && scalar_type == name(*this)) { + type = scalar_type; + } if (type != name(*this)) { - std::cerr << "File read error: wrong data type (" << type << ")." << std::endl; + std::cerr << "File read error: wrong data type (" << type << "), expected (" << name(*this) << ")." << std::endl; exit(-2); } diff --git a/utility/Makefile b/utility/Makefile index 06b4427..e7bc230 100644 --- a/utility/Makefile +++ b/utility/Makefile @@ -2,14 +2,21 @@ # GNU makefile for grid conversion programs using MMSP # Questions/comments to gruberja@gmail.com (Jason Gruber) -# VTK path +# find VTK libraries VTK_SRC = $(shell dirname $(shell locate --limit 1 vtkImageData.h)) VTK_LIB = $(shell dirname $(shell locate --limit 1 vtkCommonCore.so)) +vtklinks = -lvtkCommonCore -lvtkCommonDataModel -lvtkIOXML + +# handle special cases of VTK installation +VTK_DEB = $(shell locate --limit 1 vtkCommonCore-6.3.so) +ifneq ($(VTK_DEB), "") + VTK_LIB = $(shell dirname $(shell locate --limit 1 vtkCommonCore-6.3.so)) + vtklinks = -lvtkCommonCore-6.3 -lvtkCommonDataModel-6.3 -lvtkIOXML-6.3 +endif # compilers/flags compiler = g++ flags = -O2 -Wall -I ../include -I $(VTK_SRC) -L $(VTK_LIB) -vtklinks = -lvtkCommonCore -lvtkCommonDataModel -lvtkIOXML topo = ../algorithms/topology # conversion programs diff --git a/utility/mmsp2vti.cpp b/utility/mmsp2vti.cpp index 84b3b1e..9f3b29c 100644 --- a/utility/mmsp2vti.cpp +++ b/utility/mmsp2vti.cpp @@ -14,183 +14,183 @@ template void print_scalars(std::string filename, const MMSP::grid& GRID, const int mode) { - vtkSmartPointer vtkData = vtkSmartPointer::New(); + vtkSmartPointer scalarData = vtkSmartPointer::New(); if (dim==1) { - vtkData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), 1, 1); - vtkData->SetExtent(MMSP::x0(GRID), MMSP::x1(GRID) - 1, 0, 0, 0, 0); - vtkData->SetSpacing(MMSP::dx(GRID), 1, 1); + scalarData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), 1, 1); + scalarData->SetExtent(MMSP::x0(GRID), MMSP::x1(GRID) - 1, 0, 0, 0, 0); + scalarData->SetSpacing(MMSP::dx(GRID), 1, 1); #if VTK_MAJOR_VERSION <= 5 - vtkData->SetScalarTypeToDouble(); - vtkData->SetNumberOfScalarComponents(1); + scalarData->SetScalarTypeToDouble(); + scalarData->SetNumberOfScalarComponents(1); #else - vtkData->AllocateScalars(VTK_DOUBLE, 1); + scalarData->AllocateScalars(VTK_DOUBLE, 1); #endif MMSP::vector x(1,0); for (x[0]=MMSP::x0(GRID); x[0](vtkData->GetScalarPointer(x[0], 0, 0)); + double* pixel = static_cast(scalarData->GetScalarPointer(x[0], 0, 0)); if (mode==1) { // --mag - pixel[0] = std::sqrt(GRID(x)*GRID(x)); + *pixel = std::sqrt(GRID(x)*GRID(x)); } else { - pixel[0] = GRID(x); + *pixel = GRID(x); } } } else if (dim==2) { - vtkData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), + scalarData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), MMSP::y1(GRID)-MMSP::y0(GRID), 1); - vtkData->SetExtent(MMSP::x0(GRID), MMSP::x1(GRID) - 1, + scalarData->SetExtent(MMSP::x0(GRID), MMSP::x1(GRID) - 1, MMSP::y0(GRID), MMSP::y1(GRID) - 1, 0, 0); - vtkData->SetSpacing(MMSP::dx(GRID, 0), MMSP::dx(GRID, 1), 1); + scalarData->SetSpacing(MMSP::dx(GRID, 0), MMSP::dx(GRID, 1), 1); #if VTK_MAJOR_VERSION <= 5 - vtkData->SetScalarTypeToDouble(); - vtkData->SetNumberOfScalarComponents(1); + scalarData->SetScalarTypeToDouble(); + scalarData->SetNumberOfScalarComponents(1); #else - vtkData->AllocateScalars(VTK_DOUBLE, 1); + scalarData->AllocateScalars(VTK_DOUBLE, 1); #endif MMSP::vector x(2,0); for (x[1]=MMSP::y0(GRID); x[1](vtkData->GetScalarPointer(x[0], x[1], 0)); + double* pixel = static_cast(scalarData->GetScalarPointer(x[0], x[1], 0)); if (mode==1) { // --mag - pixel[0] = std::sqrt(GRID(x)*GRID(x)); + *pixel = std::sqrt(GRID(x)*GRID(x)); } else { - pixel[0] = GRID(x); + *pixel = GRID(x); } } } } else if (dim==3) { - vtkData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), + scalarData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), MMSP::y1(GRID)-MMSP::y0(GRID), MMSP::z1(GRID)-MMSP::z0(GRID)); - vtkData->SetExtent(MMSP::x0(GRID), MMSP::x1(GRID) - 1, + scalarData->SetExtent(MMSP::x0(GRID), MMSP::x1(GRID) - 1, MMSP::y0(GRID), MMSP::y1(GRID) - 1, MMSP::z0(GRID), MMSP::z1(GRID) - 1); - vtkData->SetSpacing(MMSP::dx(GRID, 0), MMSP::dx(GRID, 1), MMSP::dx(GRID, 2)); + scalarData->SetSpacing(MMSP::dx(GRID, 0), MMSP::dx(GRID, 1), MMSP::dx(GRID, 2)); #if VTK_MAJOR_VERSION <= 5 - vtkData->SetScalarTypeToDouble(); - vtkData->SetNumberOfScalarComponents(1); + scalarData->SetScalarTypeToDouble(); + scalarData->SetNumberOfScalarComponents(1); #else - vtkData->AllocateScalars(VTK_DOUBLE, 1); + scalarData->AllocateScalars(VTK_DOUBLE, 1); #endif MMSP::vector x(3,0); for (x[2]=MMSP::z0(GRID); x[2](vtkData->GetScalarPointer(x[0], x[1], x[2])); + double* pixel = static_cast(scalarData->GetScalarPointer(x[0], x[1], x[2])); if (mode==1) { // --mag - pixel[0] = std::sqrt(GRID(x)*GRID(x)); + *pixel = std::sqrt(GRID(x)*GRID(x)); } else { - pixel[0] = GRID(x); + *pixel = GRID(x); } } } } } - vtkData->GetPointData()->GetAbstractArray(0)->SetName("scalar_data"); + scalarData->GetPointData()->GetAbstractArray(0)->SetName("scalar_data"); vtkSmartPointer writer = vtkSmartPointer::New(); writer->SetFileName(filename.c_str()); #if VTK_MAJOR_VERSION <= 5 - writer->SetInputConnection(vtkData->GetProducerPort()); + writer->SetInputConnection(scalarData->GetProducerPort()); #else - writer->SetInputData(vtkData); + writer->SetInputData(scalarData); #endif writer->Write(); - vtkData = NULL; + scalarData = NULL; writer = NULL; } template void print_vectors(std::string filename, const MMSP::grid >& GRID, const int mode, const int field) { - vtkSmartPointer vtkData = vtkSmartPointer::New(); + vtkSmartPointer vectorData = vtkSmartPointer::New(); if (dim==1) { - vtkData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), 1, 1); - vtkData->SetExtent(MMSP::x0(GRID), MMSP::x1(GRID) - 1, 0, 0, 0, 0); - vtkData->SetSpacing(MMSP::dx(GRID), 1, 1); + vectorData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), 1, 1); + vectorData->SetExtent(MMSP::x0(GRID), MMSP::x1(GRID) - 1, 0, 0, 0, 0); + vectorData->SetSpacing(MMSP::dx(GRID), 1, 1); #if VTK_MAJOR_VERSION <= 5 - vtkData->SetScalarTypeToDouble(); + vectorData->SetScalarTypeToDouble(); if (mode==1 || mode==2 || mode==3) - vtkData->SetNumberOfScalarComponents(1); + vectorData->SetNumberOfScalarComponents(1); else - vtkData->SetNumberOfScalarComponents(MMSP::fields(GRID)); + vectorData->SetNumberOfScalarComponents(MMSP::fields(GRID)); #else if (mode==1 || mode==2 || mode==3) - vtkData->AllocateScalars(VTK_DOUBLE, 1); + vectorData->AllocateScalars(VTK_DOUBLE, 1); else - vtkData->AllocateScalars(VTK_DOUBLE, MMSP::fields(GRID)); + vectorData->AllocateScalars(VTK_DOUBLE, MMSP::fields(GRID)); #endif MMSP::vector x(1,0); for (x[0]=MMSP::x0(GRID); x[0]& v = GRID(x); - double* pixel = static_cast(vtkData->GetScalarPointer(x[0], 0, 0)); + double* pixel = static_cast(vectorData->GetScalarPointer(x[0], 0, 0)); if (mode==1) { // --mag double sum = 0.0; for (int h = 0; h < v.length(); h++) sum += v[h]*v[h]; - pixel[0] = std::sqrt(sum); + *pixel = std::sqrt(sum); } else if (mode==2) { // --max // Export index of field with greatest magnitude int max = 0; for (int h = 1; h < v.length(); h++) if (v[h] > v[max]) max = h; - pixel[0] = max; + *pixel = max; } else if (mode==3) { // --field - pixel[0] = v[field]; + *pixel = v[field]; } else { for (int h = 0; h < v.length(); h++) pixel[h] = v[h]; } } } else if (dim==2) { - vtkData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), + vectorData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), MMSP::y1(GRID)-MMSP::y0(GRID), 1); - vtkData->SetExtent(MMSP::x0(GRID), MMSP::x1(GRID) - 1, + vectorData->SetExtent(MMSP::x0(GRID), MMSP::x1(GRID) - 1, MMSP::y0(GRID), MMSP::y1(GRID) - 1, 0, 0); - vtkData->SetSpacing(MMSP::dx(GRID, 0), MMSP::dx(GRID, 1), 1); + vectorData->SetSpacing(MMSP::dx(GRID, 0), MMSP::dx(GRID, 1), 1); #if VTK_MAJOR_VERSION <= 5 - vtkData->SetScalarTypeToDouble(); + vectorData->SetScalarTypeToDouble(); if (mode==1 || mode==2 || mode==3) - vtkData->SetNumberOfScalarComponents(1); + vectorData->SetNumberOfScalarComponents(1); else - vtkData->SetNumberOfScalarComponents(MMSP::fields(GRID)); + vectorData->SetNumberOfScalarComponents(MMSP::fields(GRID)); #else if (mode==1 || mode==2 || mode==3) - vtkData->AllocateScalars(VTK_DOUBLE, 1); + vectorData->AllocateScalars(VTK_DOUBLE, 1); else - vtkData->AllocateScalars(VTK_DOUBLE, MMSP::fields(GRID)); + vectorData->AllocateScalars(VTK_DOUBLE, MMSP::fields(GRID)); #endif MMSP::vector x(2,0); for (x[1]=MMSP::y0(GRID); x[1]& v = GRID(x); - double* pixel = static_cast(vtkData->GetScalarPointer(x[0], x[1], 0)); + double* pixel = static_cast(vectorData->GetScalarPointer(x[0], x[1], 0)); if (mode==1) { // --mag double sum = 0.0; for (int h = 0; h < v.length(); h++) sum += v[h]*v[h]; - pixel[0] = std::sqrt(sum); + *pixel = std::sqrt(sum); } else if (mode==2) { // --max // Export index of field with greatest magnitude int max = 0; for (int h = 1; h < v.length(); h++) if (v[h] > v[max]) max = h; - pixel[0] = max; + *pixel = max; } else if (mode==3) { // --field - pixel[0] = v[field]; + *pixel = v[field]; } else { for (int h = 0; h < v.length(); h++) pixel[h] = v[h]; @@ -198,24 +198,24 @@ template void print_vectors(std::string filename, const MMS } } } else if (dim==3) { - vtkData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), + vectorData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), MMSP::y1(GRID)-MMSP::y0(GRID), MMSP::z1(GRID)-MMSP::z0(GRID)); - vtkData->SetExtent(MMSP::x0(GRID), MMSP::x1(GRID) - 1, + vectorData->SetExtent(MMSP::x0(GRID), MMSP::x1(GRID) - 1, MMSP::y0(GRID), MMSP::y1(GRID) - 1, MMSP::z0(GRID), MMSP::z1(GRID) - 1); - vtkData->SetSpacing(MMSP::dx(GRID, 0), MMSP::dx(GRID, 1), MMSP::dx(GRID, 2)); + vectorData->SetSpacing(MMSP::dx(GRID, 0), MMSP::dx(GRID, 1), MMSP::dx(GRID, 2)); #if VTK_MAJOR_VERSION <= 5 - vtkData->SetScalarTypeToDouble(); + vectorData->SetScalarTypeToDouble(); if (mode==1 || mode==2 || mode==3) - vtkData->SetNumberOfScalarComponents(1); + vectorData->SetNumberOfScalarComponents(1); else - vtkData->SetNumberOfScalarComponents(MMSP::fields(GRID)); + vectorData->SetNumberOfScalarComponents(MMSP::fields(GRID)); #else if (mode==1 || mode==2 || mode==3) - vtkData->AllocateScalars(VTK_DOUBLE, 1); + vectorData->AllocateScalars(VTK_DOUBLE, 1); else - vtkData->AllocateScalars(VTK_DOUBLE, MMSP::fields(GRID)); + vectorData->AllocateScalars(VTK_DOUBLE, MMSP::fields(GRID)); #endif MMSP::vector x(3,0); @@ -223,21 +223,21 @@ template void print_vectors(std::string filename, const MMS for (x[1]=MMSP::y0(GRID); x[1]& v = GRID(x); - double* pixel = static_cast(vtkData->GetScalarPointer(x[0], x[1], x[2])); + double* pixel = static_cast(vectorData->GetScalarPointer(x[0], x[1], x[2])); if (mode==1) { // --mag double sum = 0.0; for (int h = 0; h < v.length(); h++) sum += v[h]*v[h]; - pixel[0] = std::sqrt(sum); + *pixel = std::sqrt(sum); } else if (mode==2) { // --max // Export index of field with greatest magnitude int max = 0; for (int h = 1; h < v.length(); h++) if (v[h] > v[max]) max = h; - pixel[0] = max; + *pixel = max; } else if (mode==3) { // --field - pixel[0] = v[field]; + *pixel = v[field]; } else { for (int h = 0; h < v.length(); h++) pixel[h] = v[h]; @@ -246,108 +246,108 @@ template void print_vectors(std::string filename, const MMS } } } - vtkData->GetPointData()->GetAbstractArray(0)->SetName("vector_data"); + vectorData->GetPointData()->GetAbstractArray(0)->SetName("vector_data"); vtkSmartPointer writer = vtkSmartPointer::New(); writer->SetFileName(filename.c_str()); #if VTK_MAJOR_VERSION <= 5 - writer->SetInputConnection(vtkData->GetProducerPort()); + writer->SetInputConnection(vectorData->GetProducerPort()); #else - writer->SetInputData(vtkData); + writer->SetInputData(vectorData); #endif writer->Write(); - vtkData = NULL; + vectorData = NULL; writer = NULL; } template void print_sparses(std::string filename, const MMSP::grid >& GRID, const int mode, const int field) { - vtkSmartPointer vtkData = vtkSmartPointer::New(); + vtkSmartPointer sparseData = vtkSmartPointer::New(); if (dim==1) { - vtkData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), 1, 1); - vtkData->SetExtent(MMSP::x0(GRID), MMSP::x1(GRID) - 1, 0, 0, 0, 0); - vtkData->SetSpacing(MMSP::dx(GRID, 0), 1, 1); + sparseData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), 1, 1); + sparseData->SetExtent(MMSP::x0(GRID), MMSP::x1(GRID) - 1, 0, 0, 0, 0); + sparseData->SetSpacing(MMSP::dx(GRID, 0), 1, 1); #if VTK_MAJOR_VERSION <= 5 - vtkData->SetNumberOfScalarComponents(1); - vtkData->SetScalarTypeToDouble(); + sparseData->SetNumberOfScalarComponents(1); + sparseData->SetScalarTypeToDouble(); #else - vtkData->AllocateScalars(VTK_DOUBLE, 1); + sparseData->AllocateScalars(VTK_DOUBLE, 1); #endif MMSP::vector x(1,0); for (x[0]=MMSP::x0(GRID); x[0]& s = GRID(x); - double* pixel = static_cast(vtkData->GetScalarPointer(x[0], 0, 0)); + double* pixel = static_cast(sparseData->GetScalarPointer(x[0], 0, 0)); if (mode==2) { // --max // Export index of field with greatest magnitude int max = 0; for (int h = 1; h < s.length(); h++) if (s.value(h) > s.value(max)) max = h; - pixel[0] = s.index(max); + *pixel = s.index(max); } else if (mode==3) { // --field - pixel[0] = s[field]; + *pixel = s[field]; } else { // --mag is redundant for sparse double sum = 0.0; for (int h = 0; h < s.length(); h++) sum += s.value(h)*s.value(h); - pixel[0] = std::sqrt(sum); + *pixel = std::sqrt(sum); } } } else if (dim==2) { - vtkData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), + sparseData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), MMSP::y1(GRID)-MMSP::y0(GRID), 1); - vtkData->SetExtent(MMSP::x0(GRID), MMSP::x1(GRID) - 1, + sparseData->SetExtent(MMSP::x0(GRID), MMSP::x1(GRID) - 1, MMSP::y0(GRID), MMSP::y1(GRID) - 1, 0, 0); - vtkData->SetSpacing(MMSP::dx(GRID, 0), MMSP::dx(GRID, 1), 1); + sparseData->SetSpacing(MMSP::dx(GRID, 0), MMSP::dx(GRID, 1), 1); #if VTK_MAJOR_VERSION <= 5 - vtkData->SetNumberOfScalarComponents(1); - vtkData->SetScalarTypeToDouble(); + sparseData->SetNumberOfScalarComponents(1); + sparseData->SetScalarTypeToDouble(); #else - vtkData->AllocateScalars(VTK_DOUBLE, 1); + sparseData->AllocateScalars(VTK_DOUBLE, 1); #endif MMSP::vector x(2,0); for (x[1]=MMSP::y0(GRID); x[1]& s = GRID(x); - double* pixel = static_cast(vtkData->GetScalarPointer(x[0], x[1], 0)); + double* pixel = static_cast(sparseData->GetScalarPointer(x[0], x[1], 0)); if (mode==2) { // --max // Export index of field with greatest magnitude int max = 0; for (int h = 1; h < s.length(); h++) if (s.value(h) > s.value(max)) max = h; - pixel[0] = s.index(max); + *pixel = s.index(max); } else if (mode==3) { // --field - pixel[0] = s[field]; + *pixel = s[field]; } else { // --mag is redundant for sparse double sum = 0.0; for (int h = 0; h < s.length(); h++) sum += s.value(h)*s.value(h); - pixel[0] = std::sqrt(sum); + *pixel = std::sqrt(sum); } } } } else if (dim==3) { - vtkData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), + sparseData->SetDimensions(MMSP::x1(GRID)-MMSP::x0(GRID), MMSP::y1(GRID)-MMSP::y0(GRID), MMSP::z1(GRID)-MMSP::z0(GRID)); - vtkData->SetExtent(MMSP::x0(GRID), MMSP::x1(GRID) - 1, + sparseData->SetExtent(MMSP::x0(GRID), MMSP::x1(GRID) - 1, MMSP::y0(GRID), MMSP::y1(GRID) - 1, MMSP::z0(GRID), MMSP::z1(GRID) - 1); - vtkData->SetSpacing(MMSP::dx(GRID, 0), MMSP::dx(GRID, 1), MMSP::dx(GRID, 2)); + sparseData->SetSpacing(MMSP::dx(GRID, 0), MMSP::dx(GRID, 1), MMSP::dx(GRID, 2)); #if VTK_MAJOR_VERSION <= 5 - vtkData->SetNumberOfScalarComponents(1); - vtkData->SetScalarTypeToDouble(); + sparseData->SetNumberOfScalarComponents(1); + sparseData->SetScalarTypeToDouble(); #else - vtkData->AllocateScalars(VTK_DOUBLE, 1); + sparseData->AllocateScalars(VTK_DOUBLE, 1); #endif MMSP::vector x(3,0); @@ -355,38 +355,38 @@ template void print_sparses(std::string filename, const MMS for (x[1]=MMSP::y0(GRID); x[1]& s = GRID(x); - double* pixel = static_cast(vtkData->GetScalarPointer(x[0], x[1], x[2])); + double* pixel = static_cast(sparseData->GetScalarPointer(x[0], x[1], x[2])); if (mode==2) { // --max // Export index of field with greatest magnitude int max = 0; for (int h = 1; h < s.length(); h++) if (s.value(h) > s.value(max)) max = h; - pixel[0] = s.index(max); + *pixel = s.index(max); } else if (mode==3) { // --field - pixel[0] = s[field]; + *pixel = s[field]; } else { // --mag is redundant for sparse double sum = 0.0; for (int h = 0; h < s.length(); h++) sum += s.value(h)*s.value(h); - pixel[0] = std::sqrt(sum); + *pixel = std::sqrt(sum); } } } } } - vtkData->GetPointData()->GetAbstractArray(0)->SetName("sparse_data"); + sparseData->GetPointData()->GetAbstractArray(0)->SetName("sparse_data"); vtkSmartPointer writer = vtkSmartPointer::New(); writer->SetFileName(filename.c_str()); #if VTK_MAJOR_VERSION <= 5 - writer->SetInputConnection(vtkData->GetProducerPort()); + writer->SetInputConnection(sparseData->GetProducerPort()); #else - writer->SetInputData(vtkData); + writer->SetInputData(sparseData); #endif writer->Write(); - vtkData = NULL; + sparseData = NULL; writer = NULL; } From dcd0dc7c6ce743d66cb941272c2be4a8873ef86b Mon Sep 17 00:00:00 2001 From: Trevor Keller Date: Wed, 22 Aug 2018 12:57:00 -0400 Subject: [PATCH 6/8] replace mmsp2vti with library-based code --- utility/Makefile | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/utility/Makefile b/utility/Makefile index e7bc230..d110c09 100644 --- a/utility/Makefile +++ b/utility/Makefile @@ -43,12 +43,8 @@ mmsp2pvd : mmsp2pvd.cpp mmsp2tsv : mmsp2tsv.cpp $(compiler) $(flags) $< -o $@ -lz -# convert MMSP grid file to VTK Image file type -mmsp2vti : mmsp2vti.cpp - $(compiler) $(flags) $< -o $@ -lz - # convert MMSP grid file to compressed VTK Image file type -mmsp2vtz : mmsp2vti.cpp +mmsp2vti : mmsp2vti.cpp $(compiler) $(flags) $< -o $@ $(vtklinks) -lz # convert MMSP grid file to XYZ point cloud file type From 459a055275033ab46c666350e32d2c62a36a0751 Mon Sep 17 00:00:00 2001 From: Trevor Keller Date: Wed, 22 Aug 2018 13:49:55 -0400 Subject: [PATCH 7/8] compress VTK data to float instead of double (much smaller files) --- utility/mmsp2vti.cpp | 60 ++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/utility/mmsp2vti.cpp b/utility/mmsp2vti.cpp index 9f3b29c..b7e477d 100644 --- a/utility/mmsp2vti.cpp +++ b/utility/mmsp2vti.cpp @@ -21,15 +21,15 @@ template void print_scalars(std::string filename, const MMS scalarData->SetExtent(MMSP::x0(GRID), MMSP::x1(GRID) - 1, 0, 0, 0, 0); scalarData->SetSpacing(MMSP::dx(GRID), 1, 1); #if VTK_MAJOR_VERSION <= 5 - scalarData->SetScalarTypeToDouble(); + scalarData->SetScalarTypeToFloat(); scalarData->SetNumberOfScalarComponents(1); #else - scalarData->AllocateScalars(VTK_DOUBLE, 1); + scalarData->AllocateScalars(VTK_FLOAT, 1); #endif MMSP::vector x(1,0); for (x[0]=MMSP::x0(GRID); x[0](scalarData->GetScalarPointer(x[0], 0, 0)); + float* pixel = static_cast(scalarData->GetScalarPointer(x[0], 0, 0)); if (mode==1) { // --mag *pixel = std::sqrt(GRID(x)*GRID(x)); } else { @@ -45,16 +45,16 @@ template void print_scalars(std::string filename, const MMS 0, 0); scalarData->SetSpacing(MMSP::dx(GRID, 0), MMSP::dx(GRID, 1), 1); #if VTK_MAJOR_VERSION <= 5 - scalarData->SetScalarTypeToDouble(); + scalarData->SetScalarTypeToFloat(); scalarData->SetNumberOfScalarComponents(1); #else - scalarData->AllocateScalars(VTK_DOUBLE, 1); + scalarData->AllocateScalars(VTK_FLOAT, 1); #endif MMSP::vector x(2,0); for (x[1]=MMSP::y0(GRID); x[1](scalarData->GetScalarPointer(x[0], x[1], 0)); + float* pixel = static_cast(scalarData->GetScalarPointer(x[0], x[1], 0)); if (mode==1) { // --mag *pixel = std::sqrt(GRID(x)*GRID(x)); } else { @@ -71,17 +71,17 @@ template void print_scalars(std::string filename, const MMS MMSP::z0(GRID), MMSP::z1(GRID) - 1); scalarData->SetSpacing(MMSP::dx(GRID, 0), MMSP::dx(GRID, 1), MMSP::dx(GRID, 2)); #if VTK_MAJOR_VERSION <= 5 - scalarData->SetScalarTypeToDouble(); + scalarData->SetScalarTypeToFloat(); scalarData->SetNumberOfScalarComponents(1); #else - scalarData->AllocateScalars(VTK_DOUBLE, 1); + scalarData->AllocateScalars(VTK_FLOAT, 1); #endif MMSP::vector x(3,0); for (x[2]=MMSP::z0(GRID); x[2](scalarData->GetScalarPointer(x[0], x[1], x[2])); + float* pixel = static_cast(scalarData->GetScalarPointer(x[0], x[1], x[2])); if (mode==1) { // --mag *pixel = std::sqrt(GRID(x)*GRID(x)); } else { @@ -116,22 +116,22 @@ template void print_vectors(std::string filename, const MMS vectorData->SetExtent(MMSP::x0(GRID), MMSP::x1(GRID) - 1, 0, 0, 0, 0); vectorData->SetSpacing(MMSP::dx(GRID), 1, 1); #if VTK_MAJOR_VERSION <= 5 - vectorData->SetScalarTypeToDouble(); + vectorData->SetScalarTypeToFloat(); if (mode==1 || mode==2 || mode==3) vectorData->SetNumberOfScalarComponents(1); else vectorData->SetNumberOfScalarComponents(MMSP::fields(GRID)); #else if (mode==1 || mode==2 || mode==3) - vectorData->AllocateScalars(VTK_DOUBLE, 1); + vectorData->AllocateScalars(VTK_FLOAT, 1); else - vectorData->AllocateScalars(VTK_DOUBLE, MMSP::fields(GRID)); + vectorData->AllocateScalars(VTK_FLOAT, MMSP::fields(GRID)); #endif MMSP::vector x(1,0); for (x[0]=MMSP::x0(GRID); x[0]& v = GRID(x); - double* pixel = static_cast(vectorData->GetScalarPointer(x[0], 0, 0)); + float* pixel = static_cast(vectorData->GetScalarPointer(x[0], 0, 0)); if (mode==1) { // --mag double sum = 0.0; for (int h = 0; h < v.length(); h++) @@ -160,23 +160,23 @@ template void print_vectors(std::string filename, const MMS 0, 0); vectorData->SetSpacing(MMSP::dx(GRID, 0), MMSP::dx(GRID, 1), 1); #if VTK_MAJOR_VERSION <= 5 - vectorData->SetScalarTypeToDouble(); + vectorData->SetScalarTypeToFloat(); if (mode==1 || mode==2 || mode==3) vectorData->SetNumberOfScalarComponents(1); else vectorData->SetNumberOfScalarComponents(MMSP::fields(GRID)); #else if (mode==1 || mode==2 || mode==3) - vectorData->AllocateScalars(VTK_DOUBLE, 1); + vectorData->AllocateScalars(VTK_FLOAT, 1); else - vectorData->AllocateScalars(VTK_DOUBLE, MMSP::fields(GRID)); + vectorData->AllocateScalars(VTK_FLOAT, MMSP::fields(GRID)); #endif MMSP::vector x(2,0); for (x[1]=MMSP::y0(GRID); x[1]& v = GRID(x); - double* pixel = static_cast(vectorData->GetScalarPointer(x[0], x[1], 0)); + float* pixel = static_cast(vectorData->GetScalarPointer(x[0], x[1], 0)); if (mode==1) { // --mag double sum = 0.0; for (int h = 0; h < v.length(); h++) @@ -206,16 +206,16 @@ template void print_vectors(std::string filename, const MMS MMSP::z0(GRID), MMSP::z1(GRID) - 1); vectorData->SetSpacing(MMSP::dx(GRID, 0), MMSP::dx(GRID, 1), MMSP::dx(GRID, 2)); #if VTK_MAJOR_VERSION <= 5 - vectorData->SetScalarTypeToDouble(); + vectorData->SetScalarTypeToFloat(); if (mode==1 || mode==2 || mode==3) vectorData->SetNumberOfScalarComponents(1); else vectorData->SetNumberOfScalarComponents(MMSP::fields(GRID)); #else if (mode==1 || mode==2 || mode==3) - vectorData->AllocateScalars(VTK_DOUBLE, 1); + vectorData->AllocateScalars(VTK_FLOAT, 1); else - vectorData->AllocateScalars(VTK_DOUBLE, MMSP::fields(GRID)); + vectorData->AllocateScalars(VTK_FLOAT, MMSP::fields(GRID)); #endif MMSP::vector x(3,0); @@ -223,7 +223,7 @@ template void print_vectors(std::string filename, const MMS for (x[1]=MMSP::y0(GRID); x[1]& v = GRID(x); - double* pixel = static_cast(vectorData->GetScalarPointer(x[0], x[1], x[2])); + float* pixel = static_cast(vectorData->GetScalarPointer(x[0], x[1], x[2])); if (mode==1) { // --mag double sum = 0.0; for (int h = 0; h < v.length(); h++) @@ -273,15 +273,15 @@ template void print_sparses(std::string filename, const MMS sparseData->SetSpacing(MMSP::dx(GRID, 0), 1, 1); #if VTK_MAJOR_VERSION <= 5 sparseData->SetNumberOfScalarComponents(1); - sparseData->SetScalarTypeToDouble(); + sparseData->SetScalarTypeToFloat(); #else - sparseData->AllocateScalars(VTK_DOUBLE, 1); + sparseData->AllocateScalars(VTK_FLOAT, 1); #endif MMSP::vector x(1,0); for (x[0]=MMSP::x0(GRID); x[0]& s = GRID(x); - double* pixel = static_cast(sparseData->GetScalarPointer(x[0], 0, 0)); + float* pixel = static_cast(sparseData->GetScalarPointer(x[0], 0, 0)); if (mode==2) { // --max // Export index of field with greatest magnitude int max = 0; @@ -308,16 +308,16 @@ template void print_sparses(std::string filename, const MMS sparseData->SetSpacing(MMSP::dx(GRID, 0), MMSP::dx(GRID, 1), 1); #if VTK_MAJOR_VERSION <= 5 sparseData->SetNumberOfScalarComponents(1); - sparseData->SetScalarTypeToDouble(); + sparseData->SetScalarTypeToFloat(); #else - sparseData->AllocateScalars(VTK_DOUBLE, 1); + sparseData->AllocateScalars(VTK_FLOAT, 1); #endif MMSP::vector x(2,0); for (x[1]=MMSP::y0(GRID); x[1]& s = GRID(x); - double* pixel = static_cast(sparseData->GetScalarPointer(x[0], x[1], 0)); + float* pixel = static_cast(sparseData->GetScalarPointer(x[0], x[1], 0)); if (mode==2) { // --max // Export index of field with greatest magnitude int max = 0; @@ -345,9 +345,9 @@ template void print_sparses(std::string filename, const MMS sparseData->SetSpacing(MMSP::dx(GRID, 0), MMSP::dx(GRID, 1), MMSP::dx(GRID, 2)); #if VTK_MAJOR_VERSION <= 5 sparseData->SetNumberOfScalarComponents(1); - sparseData->SetScalarTypeToDouble(); + sparseData->SetScalarTypeToFloat(); #else - sparseData->AllocateScalars(VTK_DOUBLE, 1); + sparseData->AllocateScalars(VTK_FLOAT, 1); #endif MMSP::vector x(3,0); @@ -355,7 +355,7 @@ template void print_sparses(std::string filename, const MMS for (x[1]=MMSP::y0(GRID); x[1]& s = GRID(x); - double* pixel = static_cast(sparseData->GetScalarPointer(x[0], x[1], x[2])); + float* pixel = static_cast(sparseData->GetScalarPointer(x[0], x[1], x[2])); if (mode==2) { // --max // Export index of field with greatest magnitude int max = 0; From 64b2e9bf51ba94a6013ff49ec2c75bd5fe8211e5 Mon Sep 17 00:00:00 2001 From: Trevor Keller Date: Tue, 16 Oct 2018 11:59:32 -0400 Subject: [PATCH 8/8] fix VTK library detection --- utility/Makefile | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/utility/Makefile b/utility/Makefile index d110c09..48165c6 100644 --- a/utility/Makefile +++ b/utility/Makefile @@ -3,20 +3,13 @@ # Questions/comments to gruberja@gmail.com (Jason Gruber) # find VTK libraries -VTK_SRC = $(shell dirname $(shell locate --limit 1 vtkImageData.h)) -VTK_LIB = $(shell dirname $(shell locate --limit 1 vtkCommonCore.so)) +VTK_SRC = -I $(shell dirname $(shell locate --limit 1 vtkImageData.h)) +VTK_LIB = -L $(shell dirname $(shell locate --limit 1 vtkCommonCore.so)) vtklinks = -lvtkCommonCore -lvtkCommonDataModel -lvtkIOXML -# handle special cases of VTK installation -VTK_DEB = $(shell locate --limit 1 vtkCommonCore-6.3.so) -ifneq ($(VTK_DEB), "") - VTK_LIB = $(shell dirname $(shell locate --limit 1 vtkCommonCore-6.3.so)) - vtklinks = -lvtkCommonCore-6.3 -lvtkCommonDataModel-6.3 -lvtkIOXML-6.3 -endif - # compilers/flags compiler = g++ -flags = -O2 -Wall -I ../include -I $(VTK_SRC) -L $(VTK_LIB) +flags = -O2 -Wall -I ../include $(VTK_SRC) $(VTK_LIB) topo = ../algorithms/topology # conversion programs