├── .gitignore ├── LICENSE.txt ├── README.md ├── flyingEdges ├── CMakeLists.txt ├── README.md ├── doesNotWork │ ├── cuda │ │ ├── CMakeLists.txt │ │ ├── CudaMarchingCubesTables.h │ │ ├── FlyingEdgesAlgorithm.cu │ │ ├── FlyingEdgesAlgorithm.h │ │ ├── dump.cu │ │ └── main.cu │ └── thrustBad │ │ ├── CMakeLists.txt │ │ ├── FlyingEdges.h │ │ ├── Image3D.h │ │ ├── LoadImage.h │ │ ├── Thrust_Config.h │ │ ├── _main2.cu │ │ ├── main.cu │ │ ├── pass1.h │ │ ├── pass2.h │ │ ├── pass3.h │ │ ├── pass4.h │ │ ├── trim.cu │ │ └── util.h ├── mantevoCommon │ ├── YAML_Doc.cpp │ ├── YAML_Doc.hpp │ ├── YAML_Element.cpp │ └── YAML_Element.hpp ├── openmp │ ├── CMakeLists.txt │ ├── FlyingEdgesAlgorithm.cpp │ ├── FlyingEdgesAlgorithm.h │ └── main.cpp ├── serial │ ├── CMakeLists.txt │ ├── FlyingEdgesAlgorithm.cpp │ ├── FlyingEdgesAlgorithm.h │ └── main.cpp ├── thrust │ ├── CMakeLists.txt │ ├── CudaMarchingCubesTables.h │ ├── LoadImage.h │ ├── MarchingCubesTables.h │ ├── SaveTriangleMesh.h │ ├── config.h │ ├── main.cu │ └── structs.h └── util │ ├── ConvertBuffer.h │ ├── Errors.h │ ├── FlyingEdges_Config.h │ ├── Image3D.cpp │ ├── Image3D.h │ ├── LoadImage.h │ ├── MarchingCubesTables.h │ ├── SaveTriangleMesh.h │ ├── Timer.cpp │ ├── Timer.h │ ├── TriangleMesh.h │ └── TypeInfo.h ├── marchingCubes ├── CMakeLists.txt ├── README.md ├── kokkos │ ├── Makefile │ ├── README.md │ └── main.cpp ├── mantevoCommon │ ├── YAML_Doc.cpp │ ├── YAML_Doc.hpp │ ├── YAML_Element.cpp │ └── YAML_Element.hpp ├── mpi │ ├── CMakeLists.txt │ ├── README.md │ ├── main.cpp │ ├── mpi_size_type.h │ └── mpiutil.h ├── obsolete │ ├── CMakeLists.txt │ ├── allmps │ │ ├── .cproject │ │ ├── Algorithm │ │ │ ├── DuplicateRemover.cpp │ │ │ ├── DuplicateRemover.h │ │ │ ├── buildMesh.h │ │ │ ├── pointCount.cxx │ │ │ └── pointCount.h │ │ ├── CMakeLists.txt │ │ ├── Implementations │ │ │ ├── MallAlgo.cpp │ │ │ └── MallAlgo.h │ │ ├── MPIclockFunctions.h │ │ ├── Makefile │ │ └── main.cpp │ ├── common │ │ ├── .cproject │ │ ├── Algorithm │ │ │ ├── BlockMarchFunctor.cpp │ │ │ ├── BlockMarchFunctor.h │ │ │ ├── EdgeIndexer.cpp │ │ │ ├── EdgeIndexer.h │ │ │ ├── Image3DReader.cpp │ │ │ ├── Image3DReader.h │ │ │ ├── MarchAlgorithm.cpp │ │ │ ├── MarchAlgorithm.h │ │ │ ├── Ranges.h │ │ │ ├── gradients.cpp │ │ │ └── gradients.h │ │ ├── CMakeLists.txt │ │ ├── Constants │ │ │ ├── MarchingCubesTables.cpp │ │ │ ├── MarchingCubesTables.h │ │ │ ├── TypeInfo.cpp │ │ │ └── TypeInfo.h │ │ ├── Data_Obj │ │ │ ├── Image3D.cpp │ │ │ ├── Image3D.h │ │ │ ├── TriangleMesh.cpp │ │ │ ├── TriangleMesh.h │ │ │ ├── Triplet.cpp │ │ │ ├── Triplet.h │ │ │ └── tests │ │ │ │ ├── TriangleMesh_test.cpp │ │ │ │ └── triplet_test.cpp │ │ ├── GeneralContext │ │ │ ├── GeneralContext.cpp │ │ │ └── GeneralContext.h │ │ ├── IO │ │ │ ├── ConvertBuffer.h │ │ │ ├── LineStream.h │ │ │ ├── LoadBigImage.cpp │ │ │ ├── LoadBigImage.h │ │ │ ├── LoadImage3D.h │ │ │ ├── LoadImage3DMPI.cpp │ │ │ ├── LoadImage3DMPI.h │ │ │ ├── LoadImage3DMPI_test.cxx │ │ │ ├── SaveTriangleMesh.h │ │ │ └── iotest │ │ ├── Makefile │ │ ├── Reporting │ │ │ ├── IO_errors.h │ │ │ ├── Log.h │ │ │ ├── MPI_errors.h │ │ │ ├── RunTime_errors.h │ │ │ ├── Timer.cpp │ │ │ ├── Timer.h │ │ │ ├── YAML_Doc.cpp │ │ │ ├── YAML_Doc.hpp │ │ │ ├── YAML_Element.cpp │ │ │ └── YAML_Element.hpp │ │ ├── User_Interface │ │ │ ├── UI.cpp │ │ │ └── UI.h │ │ ├── includes.h │ │ └── types.h │ ├── dataGen │ │ ├── CMakeLists.txt │ │ ├── Makefile │ │ └── main.cpp │ ├── mergemp │ │ ├── .cproject │ │ ├── Algorithm │ │ │ ├── DuplicateRemover.cpp │ │ │ ├── DuplicateRemover.h │ │ │ ├── buildMesh.h │ │ │ ├── pointCount.cxx │ │ │ └── pointCount.h │ │ ├── CMakeLists.txt │ │ ├── Implementations │ │ │ ├── MergeMPAlgo.cpp │ │ │ └── MergeMPAlgo.h │ │ ├── Makefile │ │ └── main.cpp │ ├── mpi │ │ ├── .cproject │ │ ├── Algorithm │ │ │ ├── DuplicateRemover.cpp │ │ │ ├── DuplicateRemover.h │ │ │ ├── buildMesh.h │ │ │ ├── pointCount.cxx │ │ │ └── pointCount.h │ │ ├── CMakeLists.txt │ │ ├── Implementations │ │ │ ├── MpiAlgo.cpp │ │ │ └── MpiAlgo.h │ │ ├── MPIclockFunctions.h │ │ ├── Makefile │ │ └── main.cpp │ ├── openmp │ │ ├── .cproject │ │ ├── CMakeLists.txt │ │ ├── Implementations │ │ │ ├── OpenMPAlgo.cpp │ │ │ └── OpenMPAlgo.h │ │ ├── Makefile │ │ └── main.cpp │ └── serial │ │ ├── .cproject │ │ ├── CMakeLists.txt │ │ ├── Implementations │ │ ├── SerialAlgo.cpp │ │ └── SerialAlgo.h │ │ ├── Makefile │ │ └── main.cpp ├── openmp │ ├── CMakeLists.txt │ ├── README.md │ └── main.cpp ├── openmpAndMpi │ ├── CMakeLists.txt │ ├── README.md │ └── main.cpp ├── openmpDupFree │ ├── CMakeLists.txt │ ├── README.md │ └── main.cpp ├── reference ├── serial │ ├── CMakeLists.txt │ ├── README.md │ └── main.cpp └── util │ ├── ConvertBuffer.h │ ├── DuplicateRemover.h │ ├── Errors.h │ ├── Image3D.cpp │ ├── Image3D.h │ ├── LoadImage.h │ ├── MarchingCubesTables.h │ ├── SaveTriangleMesh.h │ ├── Timer.cpp │ ├── Timer.h │ ├── TriangleMesh.h │ ├── TypeInfo.h │ └── util.h ├── utilities ├── CMakeLists.txt ├── dataGen │ ├── CMakeLists.txt │ ├── main.cpp │ ├── open-simplex-noise.c │ └── open-simplex-noise.h └── tests │ ├── CMakeLists.txt │ ├── README.md │ └── SameContentsCheck.cpp └── vtkReference ├── CMakeLists.txt ├── README.md └── main.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Compiled Dynamic libraries 8 | *.so 9 | *.dylib 10 | *.dll 11 | 12 | # Compiled Static libraries 13 | *.lai 14 | *.la 15 | *.a 16 | *.lib 17 | 18 | # Executables 19 | *.exe 20 | *.out 21 | *.app 22 | 23 | # Scripts 24 | *.sh 25 | 26 | # Data 27 | *.vtk 28 | 29 | # Profiler dumps 30 | callgrind.* 31 | cachegrind.* 32 | 33 | # Run results 34 | yaml_out.* 35 | 36 | # Ignore directories 37 | build/ 38 | Data/ 39 | OO_sandbox/ 40 | OpenMP_sandbox/ 41 | design/ 42 | RemoteSystemFiles/ 43 | MPI_sandbox 44 | 45 | # Eclipse 46 | *.pydevproject 47 | .metadata 48 | .gradle 49 | bin/ 50 | tmp/ 51 | *.tmp 52 | *.bak 53 | *.swp 54 | *~.nib 55 | local.properties 56 | .settings/ 57 | .loadpath 58 | .project 59 | 60 | # Emacs temp files 61 | .#* 62 | \#*\# 63 | *~ -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | miniIsosurface miniapp License Version 1.0 2 | ======================================================================== 3 | 4 | Copyright (c) 2017 5 | National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 6 | the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 7 | certain rights in this software. 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions are 11 | met: 12 | 13 | * Redistributions of source code must retain the above copyright 14 | notice, this list of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in the 18 | documentation and/or other materials provided with the 19 | distribution. 20 | 21 | * Neither the name of Kitware nor the names of any contributors may 22 | be used to endorse or promote products derived from this software 23 | without specific prior written permission. 24 | 25 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR 29 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 30 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 31 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 32 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 33 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 34 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 35 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | ======================================================================== 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # miniIsosurface # 2 | 3 | The miniIsosurface miniapp consists of Marching Cubes and Flying Edges 4 | isosurface algorithms implemented on a variety of parallel computing 5 | paradigms. For comparison purposes, there is also an equivalent program to 6 | run the implementation in the VTK library. 7 | 8 | The seminal Marching Cubes paper: 9 | * Lorensen, William E., and Harvey E. Cline. "Marching cubes: A high 10 | resolution 3D surface construction algorithm." ACM siggraph computer 11 | graphics. Vol. 21. No. 4. ACM, 1987. 12 | 13 | The Flying Edges paper: 14 | * Schroeder, William, Rob Maynard, and Berk Geveci. "Flying edges: A 15 | high-performance scalable isocontouring algorithm." Large Data Analysis 16 | and Visualization (LDAV), 2015 IEEE 5th Symposium on. IEEE, 2015. 17 | 18 | For further information, see the README files in the 19 | [marchingCubes](marchingCubes/README.md), 20 | [flyingEdges](flyingEdges/README.md), and 21 | [vtkReference](vtkReference/README.md) directories. 22 | 23 | 24 | ## License ## 25 | 26 | miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 27 | See [LICENSE.txt](LICENSE.txt) for details. 28 | 29 | Copyright (c) 2017 30 | National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 31 | the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 32 | certain rights in this software. 33 | 34 | SCR# 2260 35 | -------------------------------------------------------------------------------- /flyingEdges/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 2 | # See LICENSE.txt for details. 3 | 4 | # Copyright (c) 2017 5 | # National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 6 | # the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 7 | # certain rights in this software. 8 | 9 | cmake_minimum_required(VERSION 2.8.12) 10 | set(CMAKE_CXX_STANDARD 11) 11 | 12 | project(flyingEdges) 13 | 14 | option(BUILD_CUDA OFF) 15 | option(BUILD_OPENMP OFF) 16 | 17 | add_subdirectory(serial) 18 | 19 | if (BUILD_CUDA) 20 | find_package(CUDA REQUIRED) 21 | add_subdirectory(thrust) 22 | #add_subdirectory(cuda) 23 | #add_subdirectory(cuda2) 24 | endif() 25 | 26 | if (BUILD_OPENMP) 27 | add_subdirectory(openmp) 28 | endif() 29 | -------------------------------------------------------------------------------- /flyingEdges/README.md: -------------------------------------------------------------------------------- 1 | # miniIsosurface/flyingEdges # 2 | 3 | The Flying Edges algorithm creates a polygonal mesh to approximate an 4 | isosurface from a three-dimensional discrete scalar field. Similar to 5 | Marching Cubes, the discrete scalar field is subdivided into uniform cubes. 6 | For each cube, the values ateach corner are compared to the isovalue to 7 | determine a possible configuration of triangles. Connected together, the 8 | triangles from all cubes will form the polygonal mesh. 9 | 10 | The difference between Flying Edges and Marching Cubes is that Flying Edges 11 | traverses the grid row by row. By doing so, a small amount of additional 12 | work reduces the total amoount of computation and the amount of memory 13 | required for the output can be determined in advance. 14 | 15 | # Build Instructions # 16 | 1. Clone the repository 17 | ``` 18 | git clone git@gitlab.sandia.gov:visMiniapps/miniIsosurface.git 19 | ``` 20 | 2. Create a build directory. flyingEdges does not require an out-of-tree 21 | build, but it is cleaner. 22 | ``` 23 | mkdir miniIsosurface/feBuild 24 | cd miniIsosurface/feBuild 25 | ``` 26 | 3. Invoke CMake from your build directory, pointing to the 27 | miniIsosurface/flyingEdges source directory. The flag `BUILD_CUDA` is 28 | required to build the thrust implementation. 29 | ``` 30 | cmake /path/to/miniIsosurface/flyingEdges 31 | ``` 32 | or 33 | ``` 34 | cmake /path/to/miniIsosurface/flyingEdges -DBUILD_CUDA=ON 35 | ``` 36 | 4. Invoke GNU make from the build directory. 37 | ``` 38 | make 39 | ``` 40 | 41 | After compiling, the following executables will be created 42 | * `./serial/flyingEdgesSerial` 43 | 44 | After compiling with `BUILD_CUDA`, the following executables will also be 45 | created 46 | * `./thrust/flyingEdgesThurst` 47 | 48 | For all executables, the `input_file`, `output_file` and `isoval` flags 49 | must be set. Upon running, each executable creates a yaml file describing 50 | performance and output characteristics. 51 | 52 | The contents of the yaml file is also printed to console. To specify the 53 | yaml output file name, the flag is `yaml_output_file`. 54 | 55 | Some executables have additional flags. To print out all flags for an 56 | executable, use the `help` flag. 57 | 58 | 59 | ## License ## 60 | 61 | miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 62 | See [LICENSE.txt](../LICENSE.txt) for details. 63 | 64 | Copyright (c) 2017 65 | National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 66 | the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 67 | certain rights in this software. 68 | -------------------------------------------------------------------------------- /flyingEdges/doesNotWork/cuda/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(target flyingEdgesCuda) 2 | 3 | set(srcs 4 | FlyingEdgesAlgorithm.cu 5 | ../util/Image3D.cpp 6 | ../util/Timer.cpp 7 | ../mantevoCommon/YAML_Doc.cpp 8 | ../mantevoCommon/YAML_Element.cpp 9 | ) 10 | 11 | set(CUDA_NVCC_FLAGS 12 | ${CUDA_NVCC_FLAGS} -std=c++11 13 | -O3 14 | ) 15 | 16 | cuda_add_executable(${target} main.cu ${srcs}) 17 | #add_executable(${target} main.cpp ${srcs}) 18 | 19 | 20 | -------------------------------------------------------------------------------- /flyingEdges/doesNotWork/thrustBad/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(target flyingEdgesCuda2) 2 | 3 | set(srcs 4 | ../util/Timer.cpp 5 | ../mantevoCommon/YAML_Doc.cpp 6 | ../mantevoCommon/YAML_Element.cpp 7 | ) 8 | 9 | set(CUDA_NVCC_FLAGS 10 | ${CUDA_NVCC_FLAGS} -std=c++11 11 | -O3 12 | ) 13 | 14 | cuda_add_executable(${target} main.cu ${srcs}) 15 | #add_executable(${target} main.cpp ${srcs}) 16 | 17 | 18 | -------------------------------------------------------------------------------- /flyingEdges/doesNotWork/thrustBad/Image3D.h: -------------------------------------------------------------------------------- 1 | #ifndef IMAGE3D_H 2 | #define IMAGE3D_H 3 | 4 | #include 5 | #include 6 | 7 | #include "Thrust_Config.h" 8 | 9 | struct Image3D 10 | { 11 | public: 12 | Image3D(thrust::host_vector data_, 13 | scalar_t const& spacingX, 14 | scalar_t const& spacingY, 15 | scalar_t const& spacingZ, 16 | scalar_t const& zeroPosX, 17 | scalar_t const& zeroPosY, 18 | scalar_t const& zeroPosZ, 19 | int const& nx, 20 | int const& ny, 21 | int const& nz) 22 | : data(data_), 23 | spacing(spacingX, spacingY, spacingZ), 24 | zeroPos(zeroPosX, zeroPosY, zeroPosZ), 25 | n(nx, ny, nz) 26 | {} 27 | 28 | int xdimension() const { return n.x; } 29 | int ydimension() const { return n.y; } 30 | int zdimension() const { return n.z; } 31 | 32 | using iterator = 33 | typename thrust::device_vector::const_iterator; 34 | 35 | iterator begin() const 36 | { 37 | return data.begin(); 38 | } 39 | 40 | iterator end() const 41 | { 42 | return data.end(); 43 | } 44 | 45 | thrust::device_vector const data; 46 | t3 spacing; 47 | t3 zeroPos; 48 | t3 n; 49 | }; 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /flyingEdges/doesNotWork/thrustBad/Thrust_Config.h: -------------------------------------------------------------------------------- 1 | #ifndef THRUST_CONFIG_H 2 | #define THRUST_CONFIG_H 3 | 4 | using scalar_t = float; 5 | using uchar = unsigned char; 6 | 7 | template 8 | struct t3 9 | { 10 | // t3() 11 | // {} 12 | // 13 | // t3(t3 const& other) 14 | // : x(x), y(y), z(z) 15 | // {} 16 | // 17 | t3(T const& x, T const& y, T const& z) 18 | : x(x), y(y), z(z) 19 | {} 20 | 21 | T x; 22 | T y; 23 | T z; 24 | }; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /flyingEdges/doesNotWork/thrustBad/pass3.h: -------------------------------------------------------------------------------- 1 | #ifndef PASS3_FE 2 | #define PASS3_FE 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | 11 | #include "Thrust_Config.h" 12 | 13 | namespace p3 { 14 | 15 | 16 | } 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /flyingEdges/doesNotWork/thrustBad/util.h: -------------------------------------------------------------------------------- 1 | #ifndef FE_UTIL_STUFF 2 | #define FE_UTIL_STUFF 3 | 4 | #include 5 | #include 6 | 7 | #include "Thrust_Config.h" 8 | 9 | namespace util{ 10 | 11 | struct step 12 | : public thrust::unary_function< 13 | int, 14 | int> 15 | { 16 | step(int const step_size) 17 | : step_size(step_size) 18 | {} 19 | 20 | __host__ __device__ 21 | int 22 | operator()(int const& idx) const 23 | { 24 | return idx*step_size; 25 | } 26 | 27 | int const step_size; 28 | }; 29 | 30 | template 31 | struct get_iter 32 | : public thrust::unary_function< 33 | int, 34 | Iter> 35 | { 36 | get_iter( 37 | Iter iter) 38 | : iter(iter) 39 | {} 40 | 41 | __host__ __device__ 42 | Iter 43 | operator()(int const& idx) const 44 | { 45 | return iter + idx; 46 | } 47 | 48 | Iter iter; 49 | }; 50 | 51 | template 52 | using get_ptr = get_iter::const_pointer>; 53 | 54 | } 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /flyingEdges/mantevoCommon/YAML_Doc.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #ifdef REDSTORM 9 | #include 10 | #include 11 | #include 12 | #endif 13 | #include "YAML_Doc.hpp" 14 | using namespace std; 15 | 16 | //set the microapp_name and version which will become part of the YAML doc. 17 | YAML_Doc::YAML_Doc(const std::string& miniApp_Name, const std::string& miniApp_Version, const std::string& destination_Directory, const std::string& destination_FileName){ 18 | miniAppName = miniApp_Name; 19 | miniAppVersion = miniApp_Version; 20 | destinationDirectory = destination_Directory; 21 | destinationFileName = destination_FileName; 22 | } 23 | 24 | //inherits the destructor from YAML_Element 25 | YAML_Doc::~YAML_Doc(void){ 26 | } 27 | 28 | /* 29 | * generates YAML from the elements of the document and saves it 30 | * to a file 31 | */ 32 | string YAML_Doc::generateYAML(){ 33 | string yaml; 34 | yaml = yaml + "Mini-Application Name: " + miniAppName + "\n"; 35 | yaml = yaml + "Mini-Application Version: " + miniAppVersion + "\n"; 36 | for(size_t i=0; iprintYAML(""); 38 | } 39 | 40 | time_t rawtime; 41 | tm * ptm; 42 | time ( &rawtime ); 43 | ptm = localtime(&rawtime); 44 | char sdate[25]; 45 | //use tm_mon+1 because tm_mon is 0 .. 11 instead of 1 .. 12 46 | sprintf (sdate,"%04d:%02d:%02d-%02d:%02d:%02d",ptm->tm_year + 1900, ptm->tm_mon+1, 47 | ptm->tm_mday, ptm->tm_hour, ptm->tm_min,ptm->tm_sec); 48 | 49 | string filename; 50 | if (destinationFileName=="") 51 | filename = miniAppName + "-" + miniAppVersion + "_"; 52 | else 53 | filename = destinationFileName; 54 | filename = filename + string(sdate) + ".yaml"; 55 | if (destinationDirectory!="" && destinationDirectory!=".") { 56 | string mkdir_cmd = "mkdir " + destinationDirectory; 57 | #ifdef REDSTORM 58 | mkdir(destinationDirectory.c_str(),0755); 59 | #else 60 | system(mkdir_cmd.c_str()); 61 | #endif 62 | filename = destinationDirectory + "/" + destinationFileName; 63 | } 64 | else 65 | filename = "./" + filename; 66 | 67 | ofstream myfile; 68 | myfile.open(filename.c_str()); 69 | myfile << yaml; 70 | myfile.close(); 71 | return yaml; 72 | } 73 | 74 | 75 | -------------------------------------------------------------------------------- /flyingEdges/openmp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 2 | # See LICENSE.txt for details. 3 | 4 | # Copyright (c) 2017 5 | # National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 6 | # the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 7 | # certain rights in this software. 8 | 9 | set(target flyingEdgesOpenMP) 10 | 11 | set(srcs 12 | FlyingEdgesAlgorithm.cpp 13 | ../util/Image3D.cpp 14 | ../util/Timer.cpp 15 | ../mantevoCommon/YAML_Doc.cpp 16 | ../mantevoCommon/YAML_Element.cpp 17 | ) 18 | 19 | find_package(OpenMP) 20 | 21 | if (NOT OPENMP_FOUND) 22 | message(SEND_ERROR 23 | "Could not find a compatible OpenMP compiler. Consider turning BUILD_OPENMP to OFF") 24 | endif() 25 | 26 | add_executable(${target} main.cpp ${srcs}) 27 | 28 | target_compile_options(${target} PUBLIC ${OpenMP_CXX_FLAGS}) 29 | set_target_properties(${target} PROPERTIES LINK_FLAGS ${OpenMP_CXX_FLAGS}) 30 | 31 | 32 | -------------------------------------------------------------------------------- /flyingEdges/openmp/FlyingEdgesAlgorithm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * flyingEdgesAlgorithm.h 3 | * 4 | * Created on: Feb 17, 2017 5 | * Author: dbourge 6 | * 7 | * miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 8 | * See LICENSE.txt for details. 9 | * 10 | * Copyright (c) 2017 11 | * National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 12 | * the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 13 | * certain rights in this software. 14 | */ 15 | 16 | #ifndef FLYINGEDGESALGORITHM_H_ 17 | #define FLYINGEDGESALGORITHM_H_ 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | #include "../util/FlyingEdges_Config.h" 25 | 26 | #include "../util/Image3D.h" 27 | #include "../util/TriangleMesh.h" 28 | 29 | struct FlyingEdgesAlgorithm 30 | { 31 | FlyingEdgesAlgorithm(util::Image3D const& image, scalar_t const& isoval) 32 | : image(image), 33 | isoval(isoval), 34 | nx(image.xdimension()), 35 | ny(image.ydimension()), 36 | nz(image.zdimension()), 37 | gridEdges(ny*nz), 38 | triCounter((ny-1)*(nz-1)), 39 | edgeCases((nx-1)*ny*nz), 40 | cubeCases((nx-1)*(ny-1)*(nz-1)) 41 | {} 42 | 43 | void pass1(); 44 | 45 | void pass2(); 46 | 47 | void pass3(); 48 | 49 | void pass4(); 50 | 51 | util::TriangleMesh moveOutput(); 52 | 53 | private: 54 | struct gridEdge 55 | { 56 | gridEdge() 57 | : xl(0), 58 | xr(0), 59 | xstart(0), 60 | ystart(0), 61 | zstart(0) 62 | {} 63 | 64 | // trim values 65 | // set on pass 1 66 | size_t xl; 67 | size_t xr; 68 | 69 | // modified on pass 2 70 | // set on pass 3 71 | size_t xstart; 72 | size_t ystart; 73 | size_t zstart; 74 | }; 75 | 76 | private: 77 | util::Image3D const& image; 78 | scalar_t const isoval; 79 | 80 | size_t const nx; // 81 | size_t const ny; // for indexing 82 | size_t const nz; // 83 | 84 | std::vector gridEdges; // size of ny*nz 85 | std::vector triCounter; // size of (ny-1)*(nz-1) 86 | 87 | std::vector edgeCases; // size (nx-1)*ny*nz 88 | std::vector cubeCases; // size (nx-1)*(ny-1)*(nz-1) 89 | 90 | std::vector > points; // 91 | std::vector > normals; // The output 92 | std::vector > tris; // 93 | 94 | private: 95 | bool isCutEdge(size_t const& i, size_t const& j, size_t const& k) const; 96 | 97 | inline uchar 98 | calcCaseEdge(bool const& prevEdge, bool const& currEdge) const; 99 | 100 | inline uchar 101 | calcCubeCase(uchar const& ec0, uchar const& ec1, 102 | uchar const& ec2, uchar const& ec3) const; 103 | 104 | inline void calcTrimValues( 105 | size_t& xl, size_t& xr, size_t const& j, size_t const& k) const; 106 | 107 | inline std::array 108 | interpolateOnCube( 109 | cube_t const& pts, 110 | scalarCube_t const& isovals, 111 | uchar const& edge) const; 112 | 113 | inline std::array 114 | interpolate( 115 | std::array const& a, 116 | std::array const& b, 117 | scalar_t const& weight) const; 118 | }; 119 | 120 | 121 | #endif 122 | -------------------------------------------------------------------------------- /flyingEdges/serial/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 2 | # See LICENSE.txt for details. 3 | 4 | # Copyright (c) 2017 5 | # National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 6 | # the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 7 | # certain rights in this software. 8 | 9 | set(target flyingEdgesSerial) 10 | 11 | set(srcs 12 | FlyingEdgesAlgorithm.cpp 13 | ../util/Image3D.cpp 14 | ../util/Timer.cpp 15 | ../mantevoCommon/YAML_Doc.cpp 16 | ../mantevoCommon/YAML_Element.cpp 17 | ) 18 | 19 | add_executable(${target} main.cpp ${srcs}) 20 | 21 | 22 | -------------------------------------------------------------------------------- /flyingEdges/serial/FlyingEdgesAlgorithm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * flyingEdgesAlgorithm.h 3 | * 4 | * Created on: Feb 17, 2017 5 | * Author: dbourge 6 | * 7 | * miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 8 | * See LICENSE.txt for details. 9 | * 10 | * Copyright (c) 2017 11 | * National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 12 | * the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 13 | * certain rights in this software. 14 | */ 15 | 16 | #ifndef FLYINGEDGESALGORITHM_H_ 17 | #define FLYINGEDGESALGORITHM_H_ 18 | 19 | #include 20 | #include 21 | 22 | #include "../util/FlyingEdges_Config.h" 23 | 24 | #include "../util/Image3D.h" 25 | #include "../util/TriangleMesh.h" 26 | 27 | struct FlyingEdgesAlgorithm 28 | { 29 | FlyingEdgesAlgorithm(util::Image3D const& image, scalar_t const& isoval) 30 | : image(image), 31 | isoval(isoval), 32 | nx(image.xdimension()), 33 | ny(image.ydimension()), 34 | nz(image.zdimension()), 35 | gridEdges(ny*nz), 36 | triCounter((ny-1)*(nz-1)), 37 | edgeCases((nx-1)*ny*nz), 38 | cubeCases((nx-1)*(ny-1)*(nz-1)) 39 | {} 40 | 41 | void pass1(); 42 | 43 | void pass2(); 44 | 45 | void pass3(); 46 | 47 | void pass4(); 48 | 49 | util::TriangleMesh moveOutput(); 50 | 51 | private: 52 | struct gridEdge 53 | { 54 | gridEdge() 55 | : xl(0), 56 | xr(0), 57 | xstart(0), 58 | ystart(0), 59 | zstart(0) 60 | {} 61 | 62 | // trim values 63 | // set on pass 1 64 | size_t xl; 65 | size_t xr; 66 | 67 | // modified on pass 2 68 | // set on pass 3 69 | size_t xstart; 70 | size_t ystart; 71 | size_t zstart; 72 | }; 73 | 74 | private: 75 | util::Image3D const& image; 76 | scalar_t const isoval; 77 | 78 | size_t const nx; // 79 | size_t const ny; // for indexing 80 | size_t const nz; // 81 | 82 | std::vector gridEdges; // size of ny*nz 83 | std::vector triCounter; // size of (ny-1)*(nz-1) 84 | 85 | std::vector edgeCases; // size (nx-1)*ny*nz 86 | std::vector cubeCases; // size (nx-1)*(ny-1)*(nz-1) 87 | 88 | std::vector > points; // 89 | std::vector > normals; // The output 90 | std::vector > tris; // 91 | 92 | private: 93 | bool isCutEdge(size_t const& i, size_t const& j, size_t const& k) const; 94 | 95 | inline uchar 96 | calcCaseEdge(bool const& prevEdge, bool const& currEdge) const; 97 | 98 | inline uchar 99 | calcCubeCase(uchar const& ec0, uchar const& ec1, 100 | uchar const& ec2, uchar const& ec3) const; 101 | 102 | inline void calcTrimValues( 103 | size_t& xl, size_t& xr, size_t const& j, size_t const& k) const; 104 | 105 | inline std::array 106 | interpolateOnCube( 107 | cube_t const& pts, 108 | scalarCube_t const& isovals, 109 | uchar const& edge) const; 110 | 111 | inline std::array 112 | interpolate( 113 | std::array const& a, 114 | std::array const& b, 115 | scalar_t const& weight) const; 116 | }; 117 | 118 | 119 | #endif 120 | -------------------------------------------------------------------------------- /flyingEdges/thrust/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 2 | # See LICENSE.txt for details. 3 | 4 | # Copyright (c) 2017 5 | # National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 6 | # the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 7 | # certain rights in this software. 8 | 9 | set(target flyingEdgesThrust) 10 | 11 | set(srcs 12 | ../util/Timer.cpp 13 | ../mantevoCommon/YAML_Doc.cpp 14 | ../mantevoCommon/YAML_Element.cpp 15 | ) 16 | 17 | set(CUDA_NVCC_FLAGS 18 | ${CUDA_NVCC_FLAGS} -std=c++11 19 | -O3 20 | ) 21 | 22 | cuda_add_executable(${target} main.cu ${srcs}) 23 | #add_executable(${target} main.cpp ${srcs}) 24 | 25 | 26 | -------------------------------------------------------------------------------- /flyingEdges/thrust/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * config.h 3 | * 4 | * miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 5 | * See LICENSE.txt for details. 6 | * 7 | * Copyright (c) 2017 8 | * National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 9 | * the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 10 | * certain rights in this software. 11 | */ 12 | 13 | #ifndef CONFIG_STUFF 14 | #define CONFIG_STUFF 15 | 16 | #include 17 | #include 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | 32 | #define RUN_ON_DEVICE 33 | 34 | /////////////////////////////////////////////////////////////////////////////// 35 | #ifdef RUN_ON_DEVICE 36 | #define __platform__ __device__ 37 | #else 38 | #define __platform__ __host__ 39 | #endif 40 | 41 | /////////////////////////////////////////////////////////////////////////////// 42 | // Basic typedef stuff 43 | using thrust::host_vector; 44 | using thrust::device_vector; 45 | 46 | template 47 | #ifdef RUN_ON_DEVICE 48 | using vector = thrust::device_vector; 49 | #else 50 | using vector = thrust::host_vector; 51 | #endif 52 | 53 | template 54 | using pointer = typename vector::pointer; 55 | 56 | template 57 | using const_pointer = typename vector::const_pointer; 58 | 59 | using scalar_t = double; 60 | using uchar = unsigned char; 61 | 62 | #ifdef RUN_ON_DEVICE 63 | auto& policy = thrust::device; 64 | #else 65 | auto& policy = thrust::host; 66 | #endif 67 | 68 | /////////////////////////////////////////////////////////////////////////////// 69 | // Table stuff 70 | #ifdef RUN_ON_DEVICE 71 | #include "CudaMarchingCubesTables.h" 72 | #define mctable cuda_util 73 | #else 74 | #include "MarchingCubesTables.h" 75 | #define mctable util 76 | #endif 77 | 78 | /////////////////////////////////////////////////////////////////////////////// 79 | // Iterator stuff 80 | using thrust::make_counting_iterator; 81 | using thrust::make_zip_iterator; 82 | using thrust::make_tuple; 83 | 84 | /////////////////////////////////////////////////////////////////////////////// 85 | // Algorithm stuff 86 | using thrust::transform; 87 | using thrust::for_each; 88 | 89 | /////////////////////////////////////////////////////////////////////////////// 90 | // Other thrust stuff 91 | using thrust::unary_function; 92 | using thrust::binary_function; 93 | using thrust::tuple; 94 | using thrust::get; 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /flyingEdges/util/ConvertBuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ConvertBuffer.h 3 | * 4 | * Created on: Jul 6, 2015 5 | * Author: sjmunn 6 | * 7 | * miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 8 | * See LICENSE.txt for details. 9 | * 10 | * Copyright (c) 2017 11 | * National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 12 | * the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 13 | * certain rights in this software. 14 | */ 15 | 16 | #ifndef UTIL_CONVERTBUFFER_H_ 17 | #define UTIL_CONVERTBUFFER_H_ 18 | 19 | #include "TypeInfo.h" 20 | #include "Errors.h" 21 | 22 | namespace util 23 | { 24 | template 25 | inline void flipEndianness(T &val) 26 | { 27 | int mid = sizeof(T) / 2; 28 | char *data = reinterpret_cast(&val); 29 | for (int i = 0; i < mid; ++i) { 30 | std::swap(data[i], data[sizeof(T) - i - 1]); 31 | } 32 | } 33 | 34 | template 35 | void convertBuffer(const SrcT *in, std::size_t nelms, DstT *out) 36 | { 37 | for (std::size_t i = 0; i < nelms; ++i) 38 | { 39 | SrcT val = *in++; 40 | flipEndianness(val); 41 | *out++ = static_cast(val); 42 | } 43 | } 44 | 45 | template 46 | void convertBufferWithTypeInfo( 47 | const char *in, const TypeInfo &ti, std::size_t nelms, T *out) 48 | { 49 | switch (ti.getId()) { 50 | case TypeInfo::ID_CHAR: 51 | convertBuffer(in, nelms, out); 52 | break; 53 | case TypeInfo::ID_SHORT: 54 | convertBuffer(reinterpret_cast(in), nelms, out); 55 | break; 56 | case TypeInfo::ID_USHORT: 57 | convertBuffer(reinterpret_cast(in), nelms, out); 58 | break; 59 | case TypeInfo::ID_INT: 60 | convertBuffer(reinterpret_cast(in), nelms, out); 61 | break; 62 | case TypeInfo::ID_FLOAT: 63 | convertBuffer(reinterpret_cast(in), nelms, out); 64 | break; 65 | case TypeInfo::ID_DOUBLE: 66 | convertBuffer(reinterpret_cast(in), nelms, out); 67 | break; 68 | //default: 69 | // throw no_type("Data type is not supported"); 70 | // break; 71 | } 72 | } 73 | } // util namespace 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /flyingEdges/util/Errors.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Errors.h 3 | * 4 | * Created on: Jul 6, 2015 5 | * Author: sjmunn 6 | * 7 | * miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 8 | * See LICENSE.txt for details. 9 | * 10 | * Copyright (c) 2017 11 | * National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 12 | * the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 13 | * certain rights in this software. 14 | */ 15 | 16 | #ifndef IO_ERRORS_H_ 17 | #define IO_ERRORS_H_ 18 | 19 | #include 20 | #include 21 | 22 | using std::size_t; 23 | 24 | namespace util { 25 | 26 | class file_not_found: public std::exception { 27 | public: 28 | file_not_found(const char* const inFileName) : 29 | fileName(inFileName) { 30 | 31 | std::cout << "file_not_found " << inFileName << std::endl; 32 | std::cout << "Given Path: " << fileName << std::endl; 33 | } 34 | 35 | private: 36 | const char* const fileName; 37 | }; 38 | 39 | class bad_format: public std::exception { 40 | public: 41 | bad_format(const char* const inMessage) : 42 | message(inMessage) { 43 | std::cout << "bad_format error with message: " << inMessage << std::endl; 44 | } 45 | 46 | private: 47 | const char* const message; 48 | }; 49 | 50 | class no_type: public std::exception { 51 | public: 52 | no_type(const char* const inMessage) : 53 | message(inMessage) { 54 | std::cout << "Type not defined error with message: " << inMessage << std::endl; 55 | } 56 | 57 | private: 58 | const char* const message; 59 | }; 60 | 61 | class not_enough_memory_allocated: public std::exception { 62 | public: 63 | not_enough_memory_allocated(const char* const inMessage) : 64 | message(inMessage) { 65 | std::cout << "Not enough memory allocated: " << inMessage << std::endl; 66 | } 67 | private: 68 | const char* const message; 69 | }; 70 | 71 | } // util namespace 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /flyingEdges/util/FlyingEdges_Config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FlyingEdges_Config.h 3 | * 4 | * miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 5 | * See LICENSE.txt for details. 6 | * 7 | * Copyright (c) 2017 8 | * National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 9 | * the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 10 | * certain rights in this software. 11 | */ 12 | 13 | #ifndef FLYINGEDGES_CONFIG_H_ 14 | #define FLYINGEDGES_CONFIG_H_ 15 | 16 | #include 17 | 18 | using std::size_t; 19 | 20 | using scalar_t = float; 21 | 22 | using uchar = unsigned char; 23 | 24 | using cube_t = std::array, 8>; 25 | using scalarCube_t = std::array; 26 | 27 | #define FE_BLOCK_WIDTH 512 28 | #define FE_BLOCK_WIDTH_PLUS_ONE 513 29 | 30 | // FE_BLOCK_WIDTH = FE_BLOCK_WIDTH_Y * FE_BLOCK_WIDTH_Z 31 | #define FE_BLOCK_WIDTH_Y 16 32 | #define FE_BLOCK_WIDTH_Z 32 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /flyingEdges/util/Image3D.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Image3D.h 3 | * 4 | * Created on: Feb 17, 2017 5 | * Author: dbourge 6 | * 7 | * miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 8 | * See LICENSE.txt for details. 9 | * 10 | * Copyright (c) 2017 11 | * National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 12 | * the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 13 | * certain rights in this software. 14 | */ 15 | 16 | #ifndef IMAGE3DREADER_H_ 17 | #define IMAGE3DREADER_H_ 18 | 19 | #include "FlyingEdges_Config.h" 20 | 21 | #include 22 | #include 23 | 24 | namespace util { 25 | 26 | class Image3D 27 | { 28 | public: 29 | // This constructor is used to construct an image of size 30 | // dimensions. 31 | Image3D(std::vector data, 32 | std::array spacing, 33 | std::array zeroPos, 34 | std::array dimensions) 35 | : data(data), spacing(spacing), zeroPos(zeroPos), 36 | nx(dimensions[0]), ny(dimensions[1]), nz(dimensions[2]) 37 | {} 38 | 39 | std::vector::const_iterator 40 | getRowIter(size_t j, size_t k) const; 41 | 42 | scalarCube_t getValsCube(size_t i, size_t j, size_t k) const; 43 | 44 | cube_t getPosCube(size_t i, size_t j, size_t k) const; 45 | 46 | cube_t getGradCube(size_t i, size_t j, size_t k) const; 47 | 48 | const scalar_t* pointer() const { return data.data(); } 49 | 50 | std::array getZeroPos() const { return zeroPos; } 51 | std::array getSpacing() const { return spacing; } 52 | 53 | size_t xdimension() const { return nx; } 54 | size_t ydimension() const { return ny; } 55 | size_t zdimension() const { return nz; } 56 | 57 | void cutDown(int const& numX) 58 | { 59 | nx = numX; 60 | std::vector newData(nx*ny*nz); 61 | std::copy(data.begin(), data.begin() + nx*ny*nz, 62 | newData.begin()); 63 | data = newData; 64 | } 65 | 66 | private: 67 | inline scalar_t 68 | getData(size_t i, size_t j, size_t k) const; 69 | 70 | std::array 71 | computeGradient(size_t i, size_t j, size_t k) const; 72 | 73 | private: 74 | std::vector data; // A vector containing scalar values 75 | // along three-dimensional space. 76 | 77 | std::array spacing; // The distance between two points in 78 | // the mesh. 79 | 80 | std::array zeroPos; // The position at index (0, 0, 0). 81 | 82 | size_t nx; // 83 | size_t ny; // The dimensions 84 | size_t nz; // 85 | }; 86 | 87 | } 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /flyingEdges/util/Timer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Timer.cpp 3 | * 4 | * Created on: Jul 17, 2015 5 | * Author: sjmunn 6 | * 7 | * miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 8 | * See LICENSE.txt for details. 9 | * 10 | * Copyright (c) 2017 11 | * National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 12 | * the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 13 | * certain rights in this software. 14 | */ 15 | 16 | #include "Timer.h" 17 | 18 | #include 19 | 20 | namespace util { 21 | 22 | Timer::Timer() { 23 | start(); 24 | } 25 | 26 | void Timer::getCurrentTimeValues(TimeValue_t &ticksCPU, 27 | TimeValue_t &wallSeconds, 28 | TimeValue_t &wallNanoseconds) const { 29 | ticksCPU = clock(); 30 | 31 | #if (_POSIX_TIMERS > 0) && (_POSIX_MONOTONIC_CLOCK > 0) 32 | struct timespec currentTime; 33 | clock_gettime(CLOCK_MONOTONIC, ¤tTime); 34 | wallSeconds = currentTime.tv_sec; 35 | wallNanoseconds = currentTime.tv_nsec; 36 | #else 37 | struct timeval currentTime; 38 | gettimeofday(¤tTime, NULL); 39 | wallSeconds = currentTime.tv_sec; 40 | wallNanoseconds = currentTime.tv_usec * 1000; 41 | #endif 42 | } 43 | 44 | void Timer::start() { 45 | totalWallTime=0; 46 | totalCPUtime=0; 47 | totalTicksCPU=0; 48 | 49 | resume(); 50 | } 51 | 52 | void Timer::pause(void) { 53 | TimeValue_t currentTicksCPU, currentWallSeconds, currentWallNanoseconds; 54 | getCurrentTimeValues(currentTicksCPU, 55 | currentWallSeconds, 56 | currentWallNanoseconds); 57 | 58 | totalTicksCPU = currentTicksCPU-startTicksCPU; 59 | totalCPUtime += (static_cast(totalTicksCPU))/CLOCKS_PER_SEC; 60 | 61 | totalWallTime += (currentWallSeconds - startWallSeconds); 62 | totalWallTime += 63 | (currentWallNanoseconds - startWallNanoseconds) / 1000000000.0; 64 | } 65 | 66 | void Timer::resume(void) { 67 | getCurrentTimeValues(startTicksCPU, startWallSeconds, startWallNanoseconds); 68 | } 69 | 70 | void Timer::stop(void) { 71 | pause(); 72 | } 73 | 74 | Timer::~Timer() { 75 | // TODO Auto-generated destructor stub 76 | } 77 | 78 | } // util namespace 79 | -------------------------------------------------------------------------------- /flyingEdges/util/Timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Timer.h 3 | * 4 | * Created on: Jul 17, 2015 5 | * Author: sjmunn 6 | * 7 | * miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 8 | * See LICENSE.txt for details. 9 | * 10 | * Copyright (c) 2017 11 | * National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 12 | * the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 13 | * certain rights in this software. 14 | */ 15 | 16 | #ifndef REPORTING_TIMER_H_ 17 | #define REPORTING_TIMER_H_ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | namespace util { 24 | 25 | class Timer { 26 | public: 27 | Timer(); 28 | //Timer(bool); 29 | virtual ~Timer(); 30 | 31 | //void startForProcess(void); 32 | 33 | void start(void); 34 | 35 | void pause(void); 36 | void resume(void); 37 | 38 | void stop(void); 39 | 40 | double getTotalTicks(void) const { return totalTicksCPU; } 41 | double getWallTime(void) const { return totalWallTime; } 42 | double getCPUtime(void) const { return totalCPUtime; } 43 | 44 | private: 45 | typedef long long TimeValue_t; 46 | 47 | TimeValue_t startTicksCPU; 48 | TimeValue_t startWallSeconds; 49 | TimeValue_t startWallNanoseconds; 50 | double totalWallTime; 51 | double totalCPUtime; 52 | TimeValue_t totalTicksCPU; 53 | 54 | void getCurrentTimeValues(TimeValue_t &ticksCPU, 55 | TimeValue_t &wallSeconds, 56 | TimeValue_t &wallNanoseconds) const; 57 | }; 58 | 59 | } // util namespace 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /flyingEdges/util/TriangleMesh.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TriangleMesh.h 3 | * 4 | * Created on: Jan 13, 2017 5 | * Author: dbourge 6 | * 7 | * miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 8 | * See LICENSE.txt for details. 9 | * 10 | * Copyright (c) 2017 11 | * National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 12 | * the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 13 | * certain rights in this software. 14 | */ 15 | 16 | #ifndef TRIANGLEMESH_H_ 17 | #define TRIANGLEMESH_H_ 18 | 19 | #include 20 | #include 21 | 22 | namespace util { 23 | 24 | class TriangleMesh 25 | { 26 | public: 27 | using PointIterator = 28 | typename std::vector >::const_iterator; 29 | using NormalIterator = 30 | typename std::vector >::const_iterator; 31 | using TriangleIterator = 32 | typename std::vector >::const_iterator; 33 | 34 | TriangleMesh() 35 | {} 36 | 37 | TriangleMesh( 38 | std::vector > && points, 39 | std::vector > && normals, 40 | std::vector > && indexTriangles) 41 | : points(std::move(points)), // std::move might be redundant 42 | normals(std::move(normals)), // but making it explicit. 43 | indexTriangles(std::move(indexTriangles)) 44 | {} 45 | 46 | std::size_t numberOfVertices() const 47 | { 48 | return points.size(); 49 | } 50 | 51 | std::size_t numberOfTriangles() const 52 | { 53 | return indexTriangles.size(); 54 | } 55 | 56 | PointIterator pointsBegin() const 57 | { 58 | return points.begin(); 59 | } 60 | 61 | PointIterator pointsEnd() const 62 | { 63 | return points.end(); 64 | } 65 | 66 | NormalIterator normalsBegin() const 67 | { 68 | return normals.begin(); 69 | } 70 | 71 | NormalIterator normalsEnd() const 72 | { 73 | return normals.end(); 74 | } 75 | 76 | TriangleIterator trianglesBegin() const 77 | { 78 | return indexTriangles.begin(); 79 | } 80 | 81 | TriangleIterator trianglesEnd() const 82 | { 83 | return indexTriangles.end(); 84 | } 85 | 86 | private: 87 | std::vector > points; 88 | std::vector > normals; 89 | std::vector > indexTriangles; 90 | }; 91 | 92 | } 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /flyingEdges/util/TypeInfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TypeInfo.h 3 | * 4 | * Created on: Jan 18, 2017 5 | * Author: dbourge, sjmunn 6 | * 7 | * miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 8 | * See LICENSE.txt for details. 9 | * 10 | * Copyright (c) 2017 11 | * National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 12 | * the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 13 | * certain rights in this software. 14 | */ 15 | 16 | #ifndef __TypeInfo_h 17 | #define __TypeInfo_h 18 | 19 | #include 20 | 21 | namespace util 22 | { 23 | static const char *names[] = { "unknown", "char", "short", "unsigned_short", 24 | "int", "float", "double" }; 25 | static const size_t sizes[] = { 0, 1, 2, 2, 4, 4, 8 }; 26 | 27 | 28 | class TypeInfo { 29 | public: 30 | enum TypeId { 31 | ID_UNKNOWN = 0, 32 | ID_CHAR, 33 | ID_SHORT, 34 | ID_USHORT, 35 | ID_INT, 36 | ID_FLOAT, 37 | ID_DOUBLE, 38 | NUM_TYPES 39 | }; 40 | 41 | TypeInfo() 42 | : id(TypeId::ID_UNKNOWN) 43 | {} 44 | 45 | TypeInfo(TypeId inId) 46 | : id(inId) 47 | {} 48 | 49 | TypeInfo(const char * typeName) 50 | : id(getTypeId(typeName)) 51 | {} 52 | 53 | TypeId getId() const { 54 | return id; 55 | } 56 | 57 | const char* name() const { 58 | return names[id]; 59 | } 60 | 61 | size_t size() const { 62 | return sizes[id]; 63 | } 64 | 65 | static TypeId getTypeId(const char *name) { 66 | std::string nm(name); 67 | for (int i = 1; i < TypeInfo::NUM_TYPES; ++i) { 68 | if (nm == names[i]) { 69 | return TypeId(i); 70 | } 71 | } 72 | return ID_UNKNOWN; 73 | } 74 | 75 | private: 76 | TypeId id; 77 | }; 78 | 79 | template 80 | TypeInfo createTemplateTypeInfo() { 81 | return TypeInfo(TypeInfo::ID_UNKNOWN); 82 | } 83 | 84 | template<> 85 | TypeInfo createTemplateTypeInfo() { 86 | return TypeInfo(TypeInfo::ID_CHAR); 87 | } 88 | 89 | template<> 90 | TypeInfo createTemplateTypeInfo() { 91 | return TypeInfo(TypeInfo::ID_SHORT); 92 | } 93 | 94 | template<> 95 | TypeInfo createTemplateTypeInfo() { 96 | return TypeInfo(TypeInfo::ID_SHORT); 97 | } 98 | 99 | template<> 100 | TypeInfo createTemplateTypeInfo() { 101 | return TypeInfo(TypeInfo::ID_INT); 102 | } 103 | 104 | template<> 105 | TypeInfo createTemplateTypeInfo() { 106 | return TypeInfo(TypeInfo::ID_FLOAT); 107 | } 108 | 109 | template<> 110 | TypeInfo createTemplateTypeInfo() { 111 | return TypeInfo(TypeInfo::ID_DOUBLE); 112 | } 113 | 114 | } 115 | 116 | #endif 117 | -------------------------------------------------------------------------------- /marchingCubes/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 2 | # See LICENSE.txt for details. 3 | 4 | # Copyright (c) 2017 5 | # National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 6 | # the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 7 | # certain rights in this software. 8 | 9 | cmake_minimum_required(VERSION 2.8.12) 10 | set(CMAKE_CXX_STANDARD 11) 11 | 12 | project(marchingCubes) 13 | 14 | option(BUILD_OPENMP OFF) 15 | option(BUILD_MPI OFF) 16 | 17 | add_subdirectory(serial) 18 | 19 | if(BUILD_OPENMP) 20 | add_subdirectory(openmp) 21 | add_subdirectory(openmpDupFree) 22 | endif() 23 | 24 | if(BUILD_MPI) 25 | add_subdirectory(mpi) 26 | endif() 27 | 28 | if(BUILD_OPENMP AND BUILD_MPI) 29 | add_subdirectory(openmpAndMpi) 30 | endif() 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /marchingCubes/README.md: -------------------------------------------------------------------------------- 1 | # miniIsosurface/marchingCubes # 2 | 3 | Marching Cubes is an algorithm that creates a polygonal mesh to approximate 4 | an isosurface from a three-dimensional discrete scalar field. The discrete 5 | scalar field is subdivided into uniform cubes. For each cube, the values at 6 | each corner are compared to the isovalue to determine a possible 7 | configuration of triangles. Connected together, the triangles from all 8 | cubes will form the polygonal mesh. 9 | 10 | Each vertex of a triangle is located on an edge of the cube. The location 11 | is approximated by linearly interpoloating from the two endpoints of that 12 | edge. Similarly, the normal value of the surface located at each vertex is 13 | approximated by linerly interpolating from the normals located at the two 14 | endpoints of the edge where the normals are equal to the gradient, 15 | approximated by the difference method. 16 | 17 | This implementation of Marching Cubes has several implementations. The 18 | reference implementation is done without any parallelization. The openmp 19 | implementation uses openMP. 20 | 21 | # C++11 usage # 22 | 23 | miniIsosurface/marchingCubes makes use of C++11 features. Namely 24 | * `auto` type-specifier 25 | * range based for-loops 26 | * The `std::vector::data` member function 27 | * The `std::vector::emplace_back` member function 28 | * The `std::array` class 29 | * The `std::to_string` function 30 | 31 | # Build Instructions # 32 | 1. Clone the repository 33 | ``` 34 | git clone git@gitlab.sandia.gov:visMiniapps/miniIsosurface.git 35 | ``` 36 | 2. Create a build directory. mantevo-marching-mubes does not require an 37 | out-of-tree build, but it is cleaner. 38 | ``` 39 | mkdir miniIsosurface/mcBuild 40 | cd miniIsosurface/mcBuild 41 | ``` 42 | 3. Invoke CMake from your build directory, pointing to the 43 | miniIsosurface/marchingCubes source directory. The two flags, 44 | `BUILD_OPENMP` and `BUILD_MPI`, must be turned on to build all 45 | implementations under the CMake build system. 46 | ``` 47 | cmake /path/to/miniIsosurface/marchingCubes -DBUILD_OPENMP=On -DBUILD_MPI=On 48 | ``` 49 | 4. Invoke GNU make from the build directory. 50 | ``` 51 | make 52 | ``` 53 | 54 | After compiling, the following executables will be created: 55 | * `./serial/serial` 56 | * `./openmp/openmp` 57 | * `./openmpDupFree/openmpDupFree` 58 | * `./mpi/mpi` 59 | * `./openmpAndMpi/openmpAndMpi` 60 | * `./tests/SameContentsCheck` 61 | 62 | For all executables, the `input_file`, `output_file` and `isoval` flags 63 | must be set. Upon running, each executable creates a yaml file describing 64 | performance and output characteristics. 65 | 66 | The contents of the yaml file is also printed to console. To specify the 67 | yaml output file name, the flag is `yaml_output_file`. 68 | 69 | Some executables have additional flags. To print out all flags for an 70 | executable, use the `help` flag. 71 | 72 | ## Kokkos Build Instructions ## 73 | 74 | The Kokkos implementation does not use CMake. See the Kokkos 75 | [README](kokkos/README.md) for the Marching Cubes with Kokkos specific 76 | build instrucions. 77 | 78 | 79 | ## License ## 80 | 81 | miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 82 | See [LICENSE.txt](../LICENSE.txt) for details. 83 | 84 | Copyright (c) 2017 85 | National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 86 | the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 87 | certain rights in this software. 88 | -------------------------------------------------------------------------------- /marchingCubes/kokkos/Makefile: -------------------------------------------------------------------------------- 1 | # miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 2 | # See LICENSE.txt for details. 3 | 4 | # Copyright (c) 2017 5 | # National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 6 | # the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 7 | # certain rights in this software. 8 | 9 | KOKKOS_PATH = ${HOME}/kokkos 10 | KOKKOS_DEVICES = "OpenMP" 11 | EXE_NAME = "kokkos" 12 | 13 | SRC = $(wildcard *.cpp) 14 | 15 | default: build 16 | echo "Start Build" 17 | 18 | ifneq (,$(findstring Cuda,$(KOKKOS_DEVICES))) 19 | CXX = ${KOKKOS_PATH}/config/nvcc_wrapper 20 | EXE = ${EXE_NAME}.cuda 21 | KOKKOS_ARCH = "SNB,Kepler35" 22 | KOKKOS_CUDA_OPTIONS = "enable_lambda" 23 | else 24 | CXX = g++ 25 | EXE = ${EXE_NAME}.host 26 | KOKKOS_ARCH = "SNB" 27 | endif 28 | 29 | CXXFLAGS = -O3 30 | LINK = ${CXX} 31 | LINKFLAGS = 32 | 33 | DEPFLAGS = -M 34 | 35 | OBJ = $(SRC:.cpp=.o) Image3D.o Timer.o YAML_Doc.o YAML_Element.o 36 | LIB = 37 | 38 | include $(KOKKOS_PATH)/Makefile.kokkos 39 | 40 | build: $(EXE) 41 | 42 | $(EXE): $(MMC_OBJ) $(OBJ) $(KOKKOS_LINK_DEPENDS) 43 | $(LINK) $(KOKKOS_LDFLAGS) $(LINKFLAGS) $(EXTRA_PATH) $(MMC_OBJ) $(OBJ) $(KOKKOS_LIBS) $(LIB) -o $(EXE) 44 | 45 | clean: kokkos-clean 46 | rm -f *.o *.cuda *.host 47 | 48 | # Compilation rules 49 | 50 | %.o:%.cpp $(KOKKOS_CPP_DEPENDS) 51 | $(CXX) $(KOKKOS_CPPFLAGS) $(KOKKOS_CXXFLAGS) $(CXXFLAGS) $(EXTRA_INC) -c $< 52 | 53 | Image3D.o : ../util/Image3D.h ../util/Image3D.cpp 54 | $(CXX) $(CXXFLAGS) -c ../util/Image3D.cpp 55 | #Image3D.o : Image3D.h Image3D.cpp 56 | # $(CXX) $(KOKKOS_CPPFLAGS) $(KOKKOS_CXXFLAGS) $(CXXFLAGS) $(EXTRA_INC) -c Image3D.cpp 57 | Timer.o : ../util/Timer.h ../util/Timer.cpp 58 | $(CXX) $(CXXFLAGS) -c ../util/Timer.cpp 59 | YAML_Doc.o : ../mantevoCommon/YAML_Doc.hpp ../mantevoCommon/YAML_Doc.cpp 60 | $(CXX) $(CXXFLAGS) -c ../mantevoCommon/YAML_Doc.cpp 61 | YAML_Element.o : ../mantevoCommon/YAML_Element.hpp ../mantevoCommon/YAML_Element.cpp 62 | $(CXX) $(CXXFLAGS) -c ../mantevoCommon/YAML_Element.cpp 63 | -------------------------------------------------------------------------------- /marchingCubes/kokkos/README.md: -------------------------------------------------------------------------------- 1 | # Marching Cubes with Kokkos Build Instructions # 2 | 3 | 1. Go to the kokkos folder within mantevo-marching-cubes 4 | ``` 5 | cd mantevo-marching-cubes/build/dir/ 6 | cd kokkos/ 7 | ``` 8 | 2. Invoke make with path to the Kokkos directory 9 | ``` 10 | make -e KOKKOS_PATH=/Path/To/kokkos/ 11 | ``` 12 | After compiling, the following executable will be created: 13 | * `./kokkos.host` 14 | 15 | # kokkos # 16 | 17 | This implementation if similar to the openmpDupFree implementation with 18 | the exception that all memory allocation for the parallel portion of the 19 | code is done ahead of time. In fact, if not enough memory is available, 20 | an exception will be thrown. The number of points and triangles allocated 21 | can be controlled by the command line flags `points_allocate` and 22 | `triangles_allocate`. Left unset, the algorithm will make a guess as to 23 | how much to allocate. 24 | 25 | ``` 26 | ./kokkos -i myImages.vtk -o outputMeshKokkos.vtk -v 1.0 -g 1012 \ 27 | -points_allocate 2000000 -triangles_allocate 4000000 28 | ``` 29 | 30 | 31 | ## License ## 32 | 33 | miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 34 | See [LICENSE.txt](../../LICENSE.txt) for details. 35 | 36 | Copyright (c) 2017 37 | National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 38 | the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 39 | certain rights in this software. 40 | -------------------------------------------------------------------------------- /marchingCubes/mantevoCommon/YAML_Doc.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #ifdef REDSTORM 9 | #include 10 | #include 11 | #include 12 | #endif 13 | #include "YAML_Doc.hpp" 14 | using namespace std; 15 | 16 | //set the microapp_name and version which will become part of the YAML doc. 17 | YAML_Doc::YAML_Doc(const std::string& miniApp_Name, const std::string& miniApp_Version, const std::string& destination_Directory, const std::string& destination_FileName){ 18 | miniAppName = miniApp_Name; 19 | miniAppVersion = miniApp_Version; 20 | destinationDirectory = destination_Directory; 21 | destinationFileName = destination_FileName; 22 | } 23 | 24 | //inherits the destructor from YAML_Element 25 | YAML_Doc::~YAML_Doc(void){ 26 | } 27 | 28 | /* 29 | * generates YAML from the elements of the document and saves it 30 | * to a file 31 | */ 32 | string YAML_Doc::generateYAML(){ 33 | string yaml; 34 | yaml = yaml + "Mini-Application Name: " + miniAppName + "\n"; 35 | yaml = yaml + "Mini-Application Version: " + miniAppVersion + "\n"; 36 | for(size_t i=0; iprintYAML(""); 38 | } 39 | 40 | time_t rawtime; 41 | tm * ptm; 42 | time ( &rawtime ); 43 | ptm = localtime(&rawtime); 44 | char sdate[25]; 45 | //use tm_mon+1 because tm_mon is 0 .. 11 instead of 1 .. 12 46 | sprintf (sdate,"%04d:%02d:%02d-%02d:%02d:%02d",ptm->tm_year + 1900, ptm->tm_mon+1, 47 | ptm->tm_mday, ptm->tm_hour, ptm->tm_min,ptm->tm_sec); 48 | 49 | string filename; 50 | if (destinationFileName=="") 51 | filename = miniAppName + "-" + miniAppVersion + "_"; 52 | else 53 | filename = destinationFileName; 54 | filename = filename + string(sdate) + ".yaml"; 55 | if (destinationDirectory!="" && destinationDirectory!=".") { 56 | string mkdir_cmd = "mkdir " + destinationDirectory; 57 | #ifdef REDSTORM 58 | mkdir(destinationDirectory.c_str(),0755); 59 | #else 60 | system(mkdir_cmd.c_str()); 61 | #endif 62 | filename = destinationDirectory + "/" + destinationFileName; 63 | } 64 | else 65 | filename = "./" + filename; 66 | 67 | ofstream myfile; 68 | myfile.open(filename.c_str()); 69 | myfile << yaml; 70 | myfile.close(); 71 | return yaml; 72 | } 73 | 74 | 75 | -------------------------------------------------------------------------------- /marchingCubes/mpi/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 2 | # See LICENSE.txt for details. 3 | 4 | # Copyright (c) 2017 5 | # National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 6 | # the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 7 | # certain rights in this software. 8 | 9 | set(target mpi) 10 | 11 | set(srcs 12 | ../util/Image3D.cpp 13 | ../util/Timer.cpp 14 | ../mantevoCommon/YAML_Element.cpp 15 | ../mantevoCommon/YAML_Doc.cpp 16 | ) 17 | 18 | find_package(MPI) 19 | 20 | if (NOT MPI_CXX_FOUND) 21 | message(SEND_ERROR 22 | "Could not find a compatible MPI compiler. Consider turning BUILD_MPI to OFF") 23 | endif() 24 | 25 | add_executable(${target} main.cpp ${srcs}) 26 | 27 | target_include_directories(${target} 28 | PUBLIC "${MPI_CXX_INCLUDE_PATH}" 29 | ) 30 | target_compile_options(${target} 31 | PUBLIC ${MPI_CXX_COMPILE_FLAGS} 32 | ) 33 | target_link_libraries(${target} 34 | ${MPI_CXX_LIBRARIES} 35 | ) 36 | set_target_properties(${target} 37 | PROPERTIES LINK_FLAGS "${MPI_CXX_LINK_FLAGS}" 38 | ) 39 | -------------------------------------------------------------------------------- /marchingCubes/mpi/README.md: -------------------------------------------------------------------------------- 1 | ## mpi ## 2 | mpirun can be used to launch this executable. The -np flag tells mpi how many 3 | processes to run. 4 | ``` 5 | mpirun -np numProcesses ./mpi/mpi -i myImage.vtk -o outputMeshMPI.vtk -v 1.0 -g 1012 6 | ``` 7 | 8 | This version of the implementation uses mpi to speed up the algorithm. The image 9 | is split up into uniform sections. Each mpi process is in charge of reading it's 10 | sections of the image from memory and running the algorihtm on those sections. 11 | When reading sections from memory, the mpi process also reads in ghost cells. 12 | 13 | There are two ways to output the mesh to file. The first is to output one mesh 14 | to each process. In the example above, if `numProcesses=2` then two files would 15 | be written, `outputMeshMPI.vtk.0` and `outputMeshMPI.vtk.1`. The other option 16 | is to set the `one_mesh` flag to 1. In that case, once the algorithm has been 17 | run and timed, the meshes from each process will be combined and one output 18 | file will be written. 19 | 20 | 21 | ## License ## 22 | 23 | miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 24 | See [LICENSE.txt](../../LICENSE.txt) for details. 25 | 26 | Copyright (c) 2017 27 | National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 28 | the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 29 | certain rights in this software. 30 | -------------------------------------------------------------------------------- /marchingCubes/mpi/mpi_size_type.h: -------------------------------------------------------------------------------- 1 | /* 2 | * mpi/main.cpp 3 | * 4 | * Created on: Jan 26, 2017 5 | * Author: dbourge 6 | * 7 | * miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 8 | * See LICENSE.txt for details. 9 | * 10 | * Copyright (c) 2017 11 | * National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 12 | * the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 13 | * certain rights in this software. 14 | */ 15 | 16 | // This is from 17 | // http://stackoverflow.com/questions/40807833/sending-size-t-type-data-with-mpi 18 | // 19 | // Need a way to use std::size_t with MPI 20 | 21 | #include 22 | #include 23 | 24 | #if SIZE_MAX == UCHAR_MAX 25 | #define my_MPI_SIZE_T MPI_UNSIGNED_CHAR 26 | #elif SIZE_MAX == USHRT_MAX 27 | #define my_MPI_SIZE_T MPI_UNSIGNED_SHORT 28 | #elif SIZE_MAX == UINT_MAX 29 | #define my_MPI_SIZE_T MPI_UNSIGNED 30 | #elif SIZE_MAX == ULONG_MAX 31 | #define my_MPI_SIZE_T MPI_UNSIGNED_LONG 32 | #elif SIZE_MAX == ULLONG_MAX 33 | #define my_MPI_SIZE_T MPI_UNSIGNED_LONG_LONG 34 | #else 35 | #error "what is happening here?" 36 | #endif 37 | 38 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.12) 2 | 3 | project(mantevo-marching-cubes) 4 | 5 | option(BUILD_OPENMP OFF) 6 | option(BUILD_MPI OFF) 7 | 8 | add_subdirectory(common) 9 | add_subdirectory(dataGen) 10 | 11 | add_subdirectory(serial) 12 | 13 | if(BUILD_OPENMP) 14 | add_subdirectory(openmp) 15 | add_subdirectory(mergemp) 16 | if(BUILD_MPI) 17 | add_subdirectory(allmps) 18 | endif() 19 | endif() 20 | 21 | if(BUILD_MPI) 22 | add_subdirectory(mpi) 23 | endif() 24 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/allmps/Algorithm/DuplicateRemover.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * DuplicateRemover.cpp 3 | * 4 | * Created on: Aug 12, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #include "DuplicateRemover.h" 9 | 10 | DuplicateRemover::DuplicateRemover(void) { 11 | // not necessary 12 | edge_sorted=false; 13 | //oldIdx_sorted=false; 14 | } 15 | 16 | void DuplicateRemover::preAllocate(unsigned nPoints) { 17 | dataArray.resize(nPoints); 18 | } 19 | 20 | void DuplicateRemover::setArrays(const PointMap_type &pointMap) { 21 | /* 22 | * This object reverses the point map 23 | * pointMap: edges pointing to point indices 24 | * edgeIdxArray : point indices pointing to edge indices 25 | */ 26 | unsigned nEdges = pointMap.size(); 27 | this->preAllocate(nEdges); 28 | // Start the clock 29 | //Timer RunTime; 30 | //#pragma omp parallel for 31 | for (PointMap_type::const_iterator it = pointMap.begin(); it != pointMap.end(); ++it) { 32 | dataArray[it->second].edgeIdx=it->first; 33 | dataArray[it->second].pointIdx=it->second; 34 | } 35 | // Stop Clock 36 | //RunTime.stop(); 37 | 38 | //Report and save YAML file 39 | //RunTime.reportTime(); 40 | } 41 | 42 | void DuplicateRemover::sortYourSelf(void) { 43 | 44 | std::sort(dataArray.begin(), dataArray.end(), ByEdgeIdx()); 45 | edge_sorted=true; 46 | //oldIdx_sorted=false; 47 | } 48 | 49 | std::vector DuplicateRemover::oldToNewIdxMap(void) { 50 | 51 | unsigned nPoints=this->getSize(); 52 | std::vector oldToNewMap; 53 | //CLOG(logDEBUG) << "!!!!!!!!!!!!!!! nPoints oldToNewIdxMap " << nPoints << " !!!!!!!!!!!!!"; 54 | oldToNewMap.resize(nPoints); 55 | 56 | //#pragma omp parallel for 57 | for(unsigned iPoint=0;iPoint3) { // Block contains at least one triangle 70 | /* 71 | * Going through the dataArray and creating new point indices for the data 72 | */ 73 | // Initialize run 74 | unsigned iEdgeIndxPrevious=dataArray[0].edgeIdx; 75 | unsigned iEdgeIndxCurrent=dataArray[1].edgeIdx; 76 | dataArray[0].newPointIdx=0; 77 | unsigned currentPointNum=0; 78 | 79 | unsigned nPoints=this->getSize(); 80 | for (unsigned iPoint=1; iPoint < nPoints; iPoint++) { 81 | iEdgeIndxCurrent=dataArray[iPoint].edgeIdx; 82 | if (iEdgeIndxCurrent!=iEdgeIndxPrevious) currentPointNum++; 83 | 84 | dataArray[iPoint].newPointIdx=currentPointNum; 85 | iEdgeIndxPrevious=iEdgeIndxCurrent; 86 | } 87 | } 88 | } 89 | 90 | DuplicateRemover& DuplicateRemover::operator+=(const unsigned increment) { 91 | 92 | //# pragma omp parallel for 93 | for (unsigned iPoint=0; iPointgetSize(); iPoint++) { 94 | this->dataArray[iPoint].pointIdx+=increment; 95 | } 96 | 97 | return *this; 98 | } 99 | 100 | DuplicateRemover& DuplicateRemover::operator+=(const DuplicateRemover&threadMap) { 101 | 102 | dataArray.insert(dataArray.end(), threadMap.dataArray.begin(), threadMap.dataArray.end()); 103 | 104 | return *this; 105 | } 106 | 107 | const unsigned DuplicateRemover::getSize(void) const { 108 | 109 | return dataArray.size(); 110 | } 111 | 112 | //DuplicateRemover::~DuplicateRemover() { 113 | // // TODO Auto-generated destructor stub 114 | //} 115 | 116 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/allmps/Algorithm/DuplicateRemover.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DuplicateRemover.h 3 | * 4 | * Created on: Aug 12, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef IMPLEMENTATIONS_MAPREVERSE_H_ 9 | #define IMPLEMENTATIONS_MAPREVERSE_H_ 10 | 11 | #include"../../common/includes.h" 12 | 13 | // Reporting Headers 14 | #include"../../common/Reporting/Log.h" 15 | #include"../../common/Reporting/IO_errors.h" 16 | #include"../../common/Reporting/Timer.h" 17 | 18 | typedef std::unordered_map PointMap_type; 19 | 20 | struct edgePointPair { 21 | unsigned edgeIdx; 22 | unsigned pointIdx; 23 | unsigned newPointIdx; 24 | }; 25 | 26 | struct ByEdgeIdx { 27 | bool operator()(const edgePointPair &left, const edgePointPair &right) { 28 | return left.edgeIdx < right.edgeIdx; 29 | } 30 | }; 31 | 32 | struct ByPointIdx { 33 | bool operator()(const edgePointPair &left, const edgePointPair &right) { 34 | return left.pointIdx < right.pointIdx; 35 | } 36 | }; 37 | 38 | class DuplicateRemover { 39 | public: 40 | DuplicateRemover(); 41 | // virtual ~DuplicateRemover(); 42 | 43 | // write 44 | void preAllocate(const unsigned); 45 | void setArrays(const PointMap_type &); 46 | void sortYourSelf(void); 47 | std::vector oldToNewIdxMap(void); 48 | DuplicateRemover& operator+=(const unsigned); 49 | DuplicateRemover& operator+=(const DuplicateRemover&); 50 | void getNewIndices(void); 51 | 52 | //read 53 | const unsigned getSize(void) const; 54 | 55 | std::vector dataArray; 56 | bool edge_sorted; 57 | //bool oldIdx_sorted; 58 | }; 59 | 60 | #endif /* IMPLEMENTATIONS_MAPREVERSE_H_ */ 61 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/allmps/Algorithm/buildMesh.h: -------------------------------------------------------------------------------- 1 | /* 2 | * buildMesh.h 3 | * 4 | * Created on: Aug 19, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef ALGORITHM_BUILDMESH_H_ 9 | #define ALGORITHM_BUILDMESH_H_ 10 | 11 | // External includes 12 | #include"../../common/includes.h" 13 | 14 | // Reporting Headers 15 | #include"../../common/Reporting/YAML_Element.hpp" 16 | #include"../../common/Reporting/YAML_Doc.hpp" 17 | #include"../../common/Reporting/Log.h" 18 | 19 | // Strategy base class 20 | #include"../../common/Data_Obj/TriangleMesh.h" 21 | 22 | #include"./DuplicateRemover.h" 23 | 24 | #include"mpi.h" 25 | 26 | template 27 | void buildMesh(TriangleMesh& newMesh, const TriangleMesh& ogMesh,DuplicateRemover& newPtMap) { 28 | /* 29 | * Iterates through the entire dataArray in newPtMap and creates 30 | * a new mesh from the new point indices in newPointIdx 31 | */ 32 | unsigned nOgPoints=newPtMap.getSize(); 33 | // As many new points as last index in the dataArray 34 | unsigned nNewPoints=newPtMap.dataArray.back().newPointIdx+1; // Because counting from 0 35 | // Allocate space in the new mesh 36 | newMesh.allocate(nNewPoints); 37 | 38 | /* 39 | * Assign all the new points and normals correctly 40 | */ 41 | for (unsigned iPoint=0; iPoint < nOgPoints; iPoint++) { 42 | 43 | unsigned newPtIndex=newPtMap.dataArray[iPoint].newPointIdx; 44 | unsigned ogPtIndex=newPtMap.dataArray[iPoint].pointIdx; 45 | const float_t * ogCoords = ogMesh.getPointPosition(ogPtIndex); 46 | const float_t * ogNormal = ogMesh.getNormalVector(ogPtIndex); 47 | 48 | newMesh.setPoint(newPtIndex,ogCoords); 49 | newMesh.setNormal(newPtIndex,ogNormal); 50 | } 51 | 52 | /* 53 | * Get the triangles 54 | */ 55 | unsigned nTriangles = ogMesh.numberOfTriangles(); 56 | std::vector oldToNewMap = newPtMap.oldToNewIdxMap(); 57 | 58 | //# pragma omp parallel for 59 | for (unsigned iTriangle=0; iTriangle < nTriangles;++iTriangle) { 60 | const unsigned *ogTriangleIdxs=ogMesh.getTriangleIndices(iTriangle); 61 | unsigned newTriangleIdxs[3]; 62 | newTriangleIdxs[0]=oldToNewMap[ogTriangleIdxs[0]]; 63 | newTriangleIdxs[1]=oldToNewMap[ogTriangleIdxs[1]]; 64 | newTriangleIdxs[2]=oldToNewMap[ogTriangleIdxs[2]]; 65 | 66 | newMesh.addTriangle(newTriangleIdxs); 67 | } 68 | 69 | } 70 | 71 | 72 | 73 | #endif /* ALGORITHM_BUILDMESH_H_ */ 74 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/allmps/Algorithm/pointCount.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pointCount.h 3 | * 4 | * Created on: Aug 7, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef ALGORITHM_POINTCOUNT_H_ 9 | #define ALGORITHM_POINTCOUNT_H_ 10 | 11 | // Common utility headers ------------- 12 | // Standard C/C++ library 13 | #include"../../common/includes.h" 14 | 15 | // Data Objects 16 | #include"../../common/types.h" 17 | 18 | typedef Triplet Point3dIdx; 19 | 20 | unsigned countPointsInVolume(const Image3D_t &, const unsigned ext[6], float_t, 21 | EdgeIndexer_t &); 22 | 23 | unsigned countPointsInBlock(const Image3D_t &, const unsigned ext[6], float_t, 24 | EdgeIndexer_t &); 25 | 26 | #endif /* ALGORITHM_POINTCOUNT_H_ */ 27 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/allmps/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(target MCAll) 2 | 3 | set(srcs 4 | Algorithm/DuplicateRemover.cpp 5 | Implementations/MallAlgo.cpp 6 | ) 7 | 8 | find_package(OpenMP) 9 | 10 | if(NOT OPENMP_FOUND) 11 | message(SEND_ERROR 12 | "Could not find a compatible OpenMP compiler. Consider turning BUILD_OPENMP to OFF") 13 | endif() 14 | 15 | find_package(MPI) 16 | 17 | if(NOT MPI_CXX_FOUND) 18 | message(SEND_ERROR 19 | "Could not find a compatible MPI compiler. Consider turning BUILD_MPI to OFF") 20 | endif() 21 | 22 | add_executable(${target} main.cpp ${srcs}) 23 | 24 | target_include_directories(${target} 25 | PUBLIC "${MPI_CXX_INCLUDE_PATH}" 26 | ) 27 | target_link_libraries(${target} 28 | mantevo_marching_cubes_common 29 | ${MPI_CXX_LIBRARIES} 30 | ) 31 | target_compile_options(${target} 32 | PUBLIC ${OpenMP_CXX_FLAGS} ${MPI_CXX_COMPILE_FLAGS} 33 | ) 34 | set_target_properties(${target} 35 | PROPERTIES LINK_FLAGS "${OpenMP_CXX_FLAGS} ${MPI_CXX_LINK_FLAGS}" 36 | ) 37 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/allmps/Implementations/MallAlgo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SerialAlgo.h 3 | * 4 | * Created on: Aug 17, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef IMPLEMENTATIONS_MERGEMPALGO_H_ 9 | #define IMPLEMENTATIONS_MERGEMPALGO_H_ 10 | 11 | // External includes 12 | #include"../../common/includes.h" 13 | 14 | // Reporting Headers 15 | #include"../../common/Reporting/YAML_Element.hpp" 16 | #include"../../common/Reporting/YAML_Doc.hpp" 17 | #include"../../common/Reporting/Log.h" 18 | #include"../../common/Reporting/Timer.h" 19 | 20 | // Strategy base class 21 | #include"../../common/Algorithm/MarchAlgorithm.h" 22 | #include"../../common/GeneralContext/GeneralContext.h" 23 | 24 | #include"../../common/Data_Obj/TriangleMesh.h" 25 | 26 | // Algorithm objects 27 | #include"../../common/Algorithm/Ranges.h" 28 | 29 | #include"../Algorithm/DuplicateRemover.h" 30 | #include"../Algorithm/buildMesh.h" 31 | 32 | // IO Object 33 | #include"../../common/IO/LoadImage3DMPI.h" 34 | 35 | //MPI 36 | #include"mpi.h" 37 | 38 | template 39 | class MallAlgo : public MarchAlgorithm { 40 | public: 41 | MallAlgo(LoadImage3DMPI &, unsigned, unsigned, Timer *); 42 | virtual ~MallAlgo(); 43 | static bool testZeroExtent(unsigned *); 44 | 45 | unsigned numBlocks(const Range oneDRange); 46 | void march(GeneralContext &); 47 | private: 48 | // These are intermediate data structures before the final 49 | // results are sent to GeneralContext 50 | unsigned grainDimX, grainDimY, grainDimZ; 51 | 52 | // MPI specific 53 | LoadImage3DMPI fileHeader; 54 | unsigned pID,processes; 55 | Timer *processTimer; 56 | }; 57 | 58 | #endif /* IMPLEMENTATIONS_MERGEMPALGO_H_ */ 59 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/allmps/MPIclockFunctions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MPIclockFunctions.h 3 | * 4 | * Created on: Aug 27, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef MPICLOCKFUNCTIONS_H_ 9 | #define MPICLOCKFUNCTIONS_H_ 10 | 11 | // Reporting 12 | #include"../common/Reporting/YAML_Element.hpp" 13 | #include"../common/Reporting/YAML_Doc.hpp" 14 | #include"../common/Reporting/Log.h" 15 | #include"../common/Reporting/Timer.h" 16 | 17 | #include"mpi.h" 18 | 19 | void collectTimesMPI(YAML_Doc &doc, Timer * runTime) { 20 | // Get the individual process ID. 21 | int pID = MPI::COMM_WORLD.Get_rank(); 22 | int nProcesses = MPI::COMM_WORLD.Get_size(); 23 | 24 | double wallTime = runTime->getWallTime(); 25 | double *wallTimes = NULL; 26 | if (pID == 0) { 27 | wallTimes = new double [nProcesses]; 28 | } 29 | MPI_Gather(&wallTime, 1, MPI_DOUBLE, wallTimes, 1, MPI_DOUBLE, 0, 30 | MPI_COMM_WORLD); 31 | double CPUtime = runTime->getWallTime(); 32 | double *CPUtimes = NULL; 33 | if (pID == 0) { 34 | CPUtimes = new double [nProcesses]; 35 | } 36 | MPI_Gather(&CPUtime, 1, MPI_DOUBLE, CPUtimes, 1, MPI_DOUBLE, 0, 37 | MPI_COMM_WORLD); 38 | 39 | // Generate a final report of the execution times 40 | if (pID == 0) { 41 | double maxWallTime=0; 42 | double totalCPU=0; 43 | for (int iPID=0;iPID(iPID)) + " CPU Time (seconds)"; 48 | std::string reportWall = "Process number, " 49 | + std::to_string(static_cast(iPID)) + " Wall Time (seconds):"; 50 | doc.add(reportCPU,wallTimes[iPID]); 51 | doc.add(reportWall,wallTimes[iPID]); 52 | if (wallTimes[iPID] > maxWallTime) maxWallTime=wallTimes[iPID]; 53 | totalCPU+=CPUtimes[iPID]; 54 | } 55 | CLOG(logYAML) << "Total CPU time: " << totalCPU; 56 | CLOG(logYAML) << "Overall wall time: " << maxWallTime; 57 | doc.add("Total CPU time: ",totalCPU); 58 | doc.add("Overall wall time: ",maxWallTime); 59 | } 60 | doc.generateYAML(); 61 | } 62 | 63 | #endif /* MPICLOCKFUNCTIONS_H_ */ 64 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/allmps/Makefile: -------------------------------------------------------------------------------- 1 | # ----------------------------------------------- 2 | # Mantevo Marching Cubes OpenMP Implementation 3 | # with Merger algorithm 4 | # 5 | # Author: sjmunn@sandia.gov 6 | # Date : 2015-07-31 7 | # 8 | # Changelog : 9 | # 2015-07-31 - created 10 | # ----------------------------------------------- 11 | 12 | # ========== Macros ============================= 13 | 14 | # project name (generate executable with this name) 15 | TARGET = MCAll.exe 16 | 17 | # Compiler and flags 18 | CC = mpic++ 19 | CXXFLAGS = -O2 -lrt -fopenmp -std=c++0x 20 | #CXXFLAGS = -O0 -g -Wall -Wconversion -fopenmp -std=c++0x 21 | 22 | # Source and build directories 23 | SRCDIRS = Algorithm Implementations User_Interface 24 | BUILD_DIRECTORY = build 25 | BUILDDIR = $(BUILD_DIRECTORY) 26 | 27 | # Utility object code 28 | UTILS_DIR = ../common/build 29 | 30 | # Get source code files and generate object names 31 | SOURCES := $(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.cpp)) 32 | OBJECTS := $(addprefix $(BUILDDIR)/,$(notdir $(SOURCES:.cpp=.o))) 33 | UTILS_OBJ := $(wildcard $(UTILS_DIR)/*.o) 34 | 35 | # ========== Compiler Rules ===================== 36 | 37 | # Linker commands 38 | 39 | all: main.o $(OBJECTS) $(UTILS_OBJ) 40 | @echo "Linking object files..."; 41 | @$(CC) $(CXXFLAGS) $(BUILDDIR)/main.o $(UTILS_OBJ) $(OBJECTS) -o $(BUILDDIR)/$(TARGET) $(GPERF_FLAG); 42 | @echo "Compiled and linked "$(BUILDDIR)/$(TARGET)" successfully!" 43 | 44 | # Compiler commands 45 | 46 | main.o: main.cpp 47 | @mkdir -p $(BUILDDIR); 48 | @echo "Compiling "$(BUILDDIR)/$@; 49 | @$(CC) $(CXXFLAGS) -c main.cpp -o $(BUILDDIR)/$@; 50 | 51 | # General purpose object code compiler 52 | $(BUILDDIR)/%.o: ./*/%.cpp 53 | @mkdir -p $(BUILDDIR); 54 | @echo "Compiling "$@; 55 | @$(CC) $(CXXFLAGS) -c $< -o $@; 56 | 57 | # ========== Cleanup Rules ====================== 58 | 59 | .PHONEY: clean 60 | clean: 61 | rm -f $(BUILDDIR)/*.o; 62 | 63 | .PHONEY: clean_run_data 64 | clean_run_data: 65 | rm -f yaml_out.*; 66 | rm -f callgrind.*; 67 | 68 | .PHONEY: deepclean 69 | deepclean: clean clean_run_data 70 | rm -rf $(BUILDDIR); 71 | 72 | # ========== Debug Rules ======================== 73 | 74 | debug: 75 | @echo "Using compiler: " 76 | @echo $(CC) 77 | @echo "With flags: " 78 | @echo $(CXXFLAGS) 79 | @echo "Source code directories: " 80 | @echo $(SRCDIRS); 81 | @echo "Source code files: " 82 | @echo $(SOURCES); 83 | @echo "Object files: " 84 | @echo $(OBJECTS); 85 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/allmps/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * main.cpp 3 | * 4 | * Created on: Jul 2, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | // Common utility headers ------------- 9 | // Standard C/C++ library 10 | #include"../common/includes.h" 11 | 12 | // File i/o 13 | #include"../common/IO/LoadImage3DMPI.h" 14 | #include"../common/IO/SaveTriangleMesh.h" 15 | 16 | // Reporting 17 | #include"../common/Reporting/YAML_Element.hpp" 18 | #include"../common/Reporting/YAML_Doc.hpp" 19 | #include"../common/Reporting/Log.h" 20 | #include"../common/Reporting/Timer.h" 21 | 22 | #include"../common/User_Interface/UI.h" 23 | 24 | // Data Objects 25 | #include"../common/types.h" 26 | 27 | // Local implementation headers ------- 28 | // Algorithm 29 | #include"./MPIclockFunctions.h" 30 | #include "Implementations/MallAlgo.h" 31 | 32 | int main(int argc, char* argv[]) { 33 | 34 | LOG::ReportingLevel() = logDEBUG1; // Debug level is hard coded 35 | 36 | unsigned id; 37 | unsigned nProcesses; 38 | 39 | // Initialize MPI 40 | MPI::Init(argc,argv); 41 | // Get the number of processes. 42 | nProcesses = MPI::COMM_WORLD.Get_size(); 43 | // Get the individual process ID. 44 | id = MPI::COMM_WORLD.Get_rank(); 45 | 46 | // Initialize the user interface 47 | UI mainUI(argc,argv); 48 | 49 | // Create data object 50 | GeneralContext data; 51 | 52 | // Only load the header file, MpiAlgo will read the rest 53 | LoadImage3DMPI fileHeader; 54 | fileHeader.loadHeader(mainUI.getFile()); 55 | fileHeader.setSperateData(mainUI.getDataFile()); 56 | 57 | // Report file data characteristics 58 | CLOG(logYAML) << "Volume image data file path: " << mainUI.getFile(); 59 | data.doc.add("Volume image data file path", mainUI.getFile()); 60 | fileHeader.report(data.doc); 61 | 62 | // Start the clock 63 | Timer runTime; 64 | // Execute the marching cubes implementation 65 | data.isoval=mainUI.getIsoVal(); 66 | MallAlgo algorithm(fileHeader,id,nProcesses,&runTime); 67 | data.setAlgorithm(&algorithm); 68 | data.march(); 69 | // Stop Clock 70 | runTime.stop(); 71 | 72 | //Report and save YAML file 73 | collectTimesMPI(data.doc,&runTime); 74 | 75 | // Save the result 76 | const char * baseName= mainUI.outFile(); 77 | std::string outFile = baseName; 78 | outFile = outFile + "." + std::to_string(static_cast(id)); 79 | saveTriangleMesh(&(data.mesh), outFile.c_str()); 80 | 81 | // 82 | // Terminate MPI. 83 | // 84 | MPI::Finalize(); 85 | return 0; 86 | } 87 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/Algorithm/BlockMarchFunctor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BlockMarchFunctor.h 3 | * 4 | * Created on: Aug 19, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef BLOCKMARCHFUNCTOR_H_ 9 | #define BLOCKMARCHFUNCTOR_H_ 10 | 11 | // External includes 12 | #include"../includes.h" 13 | 14 | // Reporting Headers 15 | #include"../Reporting/Log.h" 16 | 17 | #include"../Constants/MarchingCubesTables.h" 18 | #include"./gradients.h" 19 | #include"./EdgeIndexer.h" 20 | 21 | #include"./gradients.h" 22 | 23 | template 24 | class BlockMarchFunctor { 25 | typedef Image3DReader Image3DReader_type; 26 | typedef TriangleMesh TriangleMesh_type; 27 | typedef EdgeIndexer EdgeIndexer_type; 28 | typedef std::unordered_map PointMap_type; 29 | 30 | typedef Triplet PositionVector_type; 31 | typedef Triplet IndexTriplet_type; 32 | public: 33 | BlockMarchFunctor(Image3DReader_type &vol, const unsigned blockExt[6], 34 | T isoval, PointMap_type &pointMap, EdgeIndexer_type &edgeIndices, 35 | TriangleMesh_type &mesh); 36 | virtual ~BlockMarchFunctor(); 37 | private: 38 | static T lerp(T a, T b, T w); 39 | static int findCaseId(T*,T); 40 | 41 | // ===== Block parameters =================== 42 | const unsigned *dims; 43 | const T *origin; 44 | const T *spacing; 45 | unsigned sliceSize; 46 | 47 | // ===== Iteration position identifiers ===== 48 | unsigned xidx, yidx, zidx; 49 | 50 | // ===== Cell processing variable =========== 51 | int cellCaseId; 52 | }; 53 | 54 | #endif /* BLOCKMARCHFUNCTOR_H_ */ 55 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/Algorithm/EdgeIndexer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TriMeshWithEdges.h 3 | * 4 | * Created on: Jul 28, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef EDGEINDEXER_H_ 9 | #define EDGEINDEXER_H_ 10 | 11 | #include"../includes.h" 12 | 13 | #include"../Data_Obj/Triplet.h" 14 | // Reporting Headers 15 | #include"../Reporting/Log.h" 16 | #include"../Reporting/RunTime_errors.h" 17 | 18 | typedef Triplet Point3dIdx; 19 | 20 | template 21 | class EdgeIndexer { 22 | 23 | typedef Triplet Point3d; 24 | typedef Triplet Vector3d; 25 | typedef Triplet Triangle; 26 | public: 27 | EdgeIndexer(unsigned *); 28 | virtual ~EdgeIndexer() {}; 29 | 30 | // Adding to points to the edge index 31 | unsigned getEdgeIndex(unsigned, unsigned, unsigned, int) const; 32 | void getPointCoordinates(unsigned,Point3dIdx&,Point3dIdx&) const; 33 | 34 | // This function is not a member b/c we keep I/O separate 35 | template friend void saveTriangleMesh(const EdgeIndexer *, const char *); 36 | 37 | unsigned nAllEdges; 38 | unsigned rangeX, rangeY, rangeZ; 39 | unsigned nXedges, nXYedges; 40 | private: 41 | // Set of 3 edge index calculators 42 | unsigned edgeIndexXaxis(unsigned, unsigned, unsigned, int) const; 43 | unsigned edgeIndexYaxis(unsigned, unsigned, unsigned, int) const; 44 | unsigned edgeIndexZaxis(unsigned, unsigned, unsigned, int) const; 45 | }; 46 | 47 | #endif /* EDGEINDEXER_H_ */ 48 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/Algorithm/Image3DReader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Image3DReader.h 3 | * 4 | * Created on: Aug 21, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef IMAGE3DREADER_H_ 9 | #define IMAGE3DREADER_H_ 10 | 11 | #include"../includes.h" 12 | 13 | // Reporting Headers 14 | #include"../Reporting/YAML_Element.hpp" 15 | #include"../Reporting/YAML_Doc.hpp" 16 | #include"../Reporting/Log.h" 17 | 18 | // Data Objects 19 | #include"../Data_Obj/Image3D.h" 20 | 21 | template 22 | class Image3DReader { 23 | public: 24 | Image3DReader(Image3D*); 25 | virtual ~Image3DReader(); 26 | 27 | // Read the Image3D object 28 | void setImage3DOutputBuffers(unsigned, unsigned,unsigned); 29 | void getVertexValues(T *,unsigned,unsigned); 30 | 31 | void getValsForGradient(T (& x)[3][2], T (& run)[3], const unsigned, const unsigned, const unsigned) const; 32 | 33 | Image3D *imageData; 34 | private: 35 | // Prevent object copying (would cost too much memory 36 | Image3DReader(const Image3DReader&); // no implementation 37 | Image3DReader& operator=(const Image3DReader&); // no implementation 38 | 39 | /* ===== Reading image object =============== 40 | * Collection of buffers to allow the Image3D 41 | * object to read itself efficiently. 42 | ==========================================*/ 43 | unsigned bufferIdx; 44 | /* 45 | * 4 buffers improve cache efficiency 46 | * this speeds up run time significantly 47 | */ 48 | const T *X1buffer; 49 | const T *X2buffer; 50 | const T *X3buffer; 51 | const T *X4buffer; 52 | 53 | bool isMPIimage; 54 | }; 55 | 56 | #endif /* IMAGE3DREADER_H_ */ 57 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/Algorithm/MarchAlgorithm.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * MarchAlgorithm.cpp 3 | * 4 | * Created on: Aug 17, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #include "MarchAlgorithm.h" 9 | 10 | template 11 | MarchAlgorithm::MarchAlgorithm() { 12 | globalEdgeIndices=0; 13 | } 14 | 15 | template 16 | MarchAlgorithm::~MarchAlgorithm() { 17 | // TODO Auto-generated destructor stub 18 | } 19 | 20 | template 21 | void MarchAlgorithm::setGlobalVariables(GeneralContext &inData) { 22 | globalEdgeIndices = new EdgeIndexer(inData.ext); 23 | //unsigned mapSize = globalEdgeIndices->nAllEdges / 8; 24 | //globalPointMap.rehash(mapSize); 25 | } 26 | 27 | template 28 | void MarchAlgorithm::extractIsosurfaceFromBlock(Image3D_type &vol, const unsigned blockExt[6], 29 | T isoval, PointMap_type &pointMap, EdgeIndexer_type &edgeIndices, 30 | TriangleMesh_type &mesh) { 31 | 32 | Image3DReader volReader(&vol); 33 | BlockMarchFunctor marchingCubes(volReader, blockExt, isoval, pointMap, edgeIndices, mesh); 34 | } 35 | 36 | #include"../GeneralContext/GeneralContext.h" 37 | // Must instantiate class for separate compilation 38 | template class MarchAlgorithm ; 39 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/Algorithm/MarchAlgorithm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MarchAlgorithm.h 3 | * 4 | * Created on: Aug 17, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef MARCHALGORITHM_H_ 9 | #define MARCHALGORITHM_H_ 10 | 11 | // External includes 12 | #include"../includes.h" 13 | 14 | // Reporting Headers 15 | #include"../Reporting/Log.h" 16 | 17 | #include"../Constants/MarchingCubesTables.h" 18 | #include"./gradients.h" 19 | #include"./EdgeIndexer.h" 20 | 21 | #include"./Image3DReader.h" 22 | #include"./BlockMarchFunctor.h" 23 | 24 | template class GeneralContext; 25 | 26 | template 27 | class MarchAlgorithm { 28 | 29 | typedef Image3D Image3D_type; 30 | typedef TriangleMesh TriangleMesh_type; 31 | typedef EdgeIndexer EdgeIndexer_type; 32 | typedef std::unordered_map PointMap_type; 33 | 34 | typedef Triplet PositionVector_type; 35 | typedef Triplet IndexTriplet_type; 36 | public: 37 | MarchAlgorithm(); 38 | virtual ~MarchAlgorithm(); 39 | 40 | virtual void march(GeneralContext&) = 0; 41 | 42 | void setGlobalVariables(GeneralContext &); 43 | 44 | void extractIsosurfaceFromBlock(Image3D_type &, const unsigned [6], 45 | T, PointMap_type &, EdgeIndexer_type &, 46 | TriangleMesh_type &); 47 | 48 | EdgeIndexer_type *globalEdgeIndices; 49 | PointMap_type globalPointMap; 50 | }; 51 | 52 | #endif /* MARCHALGORITHM_H_ */ 53 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/Algorithm/Ranges.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ranges.h 3 | * 4 | * Created on: Jul 10, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef ALGORITHM_RANGES_H_ 9 | #define ALGORITHM_RANGES_H_ 10 | 11 | class Range { 12 | public: 13 | Range() : 14 | from(0), to(0), gsize(1) { 15 | } 16 | Range(unsigned inFrom, unsigned inTo, unsigned inGsize = 1) : 17 | from(inFrom), to(inTo), gsize(inGsize) { 18 | } 19 | 20 | unsigned begin() const { 21 | return from; 22 | } 23 | 24 | unsigned end() const { 25 | return to; 26 | } 27 | 28 | unsigned grain() const { 29 | return gsize; 30 | } 31 | 32 | private: 33 | unsigned from, to, gsize; 34 | }; 35 | 36 | class Range2D { 37 | public: 38 | Range2D() : 39 | r(0, 0), c(0, 0) { 40 | } 41 | Range2D(unsigned rfrom, unsigned rto, unsigned rgrain, unsigned cfrom, 42 | unsigned cto, unsigned cgrain) : 43 | r(rfrom, rto, rgrain), c(cfrom, cto, cgrain) { 44 | } 45 | Range2D(unsigned rfrom, unsigned rto, unsigned cfrom, unsigned cto) : 46 | r(rfrom, rto), c(cfrom, cto) { 47 | } 48 | 49 | const Range& rows() const { 50 | return r; 51 | } 52 | 53 | const Range& cols() const { 54 | return c; 55 | } 56 | 57 | private: 58 | Range r, c; 59 | }; 60 | 61 | class Range3D { 62 | public: 63 | Range3D() : 64 | p(0, 0), r(0, 0), c(0, 0) { 65 | } 66 | Range3D(unsigned pfrom, unsigned pto, unsigned pgrain, unsigned rfrom, 67 | unsigned rto, unsigned rgrain, unsigned cfrom, unsigned cto, 68 | unsigned cgrain) : 69 | p(pfrom, pto, pgrain), r(rfrom, rto, rgrain), c(cfrom, cto, cgrain) { 70 | } 71 | Range3D(unsigned pfrom, unsigned pto, unsigned rfrom, unsigned rto, 72 | unsigned cfrom, unsigned cto) : 73 | p(pfrom, pto), r(rfrom, rto), c(cfrom, cto) { 74 | } 75 | 76 | const Range& pages() const { 77 | return p; 78 | } 79 | 80 | const Range& rows() const { 81 | return r; 82 | } 83 | 84 | const Range& cols() const { 85 | return c; 86 | } 87 | 88 | void extent(unsigned * inExtent) const { 89 | inExtent[0] = this->c.begin(); 90 | inExtent[1] = this->c.end() - 1; 91 | inExtent[2] = this->r.begin(); 92 | inExtent[3] = this->r.end() - 1; 93 | inExtent[4] = this->p.begin(); 94 | inExtent[5] = this->p.end() - 1; 95 | } 96 | 97 | private: 98 | Range p, r, c; 99 | }; 100 | 101 | #endif /* ALGORITHM_RANGES_H_ */ 102 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/Algorithm/gradients.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gradients.cpp 3 | * 4 | * Created on: Aug 6, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #include"gradients.h" 9 | 10 | template 11 | void computeGradient(unsigned xidx, unsigned yidx, unsigned zidx, const Image3DReader* imageVolume, T grad[3]) { 12 | T x[3][2]; 13 | T run[3]; 14 | imageVolume->getValsForGradient(x,run,xidx,yidx,zidx); 15 | 16 | for (int iAxis=0;iAxis<3;++iAxis) { 17 | grad[iAxis]=(x[iAxis][1]-x[iAxis][0]) / run[iAxis]; 18 | } 19 | } 20 | 21 | template 22 | void computeAllGradients (unsigned &xidx, unsigned &yidx, unsigned &zidx, const Image3DReader* imgVol, T (& grad)[8][3]) { 23 | computeGradient(xidx, yidx, zidx, imgVol, grad[0]); 24 | computeGradient(xidx + 1, yidx, zidx, imgVol, grad[1]); 25 | computeGradient(xidx + 1, yidx + 1, zidx, imgVol, grad[2]); 26 | computeGradient(xidx, yidx + 1, zidx, imgVol, grad[3]); 27 | computeGradient(xidx, yidx, zidx + 1, imgVol, grad[4]); 28 | computeGradient(xidx + 1, yidx, zidx + 1, imgVol, grad[5]); 29 | computeGradient(xidx + 1, yidx + 1, zidx + 1, imgVol, grad[6]); 30 | computeGradient(xidx, yidx + 1, zidx + 1, imgVol, grad[7]); 31 | } 32 | 33 | 34 | // Must explicitly instantiate template functions for separate compiling to work 35 | template void computeGradient (unsigned xidx, unsigned yidx, unsigned zidx, const Image3DReader*, float_t grad[3]); 36 | 37 | template void computeAllGradients (unsigned &xidx, unsigned &yidx, unsigned &zidx, const Image3DReader*, float_t (& grad)[8][3]); 38 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/Algorithm/gradients.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gradients.h 3 | * 4 | * Created on: Aug 6, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef ALGORITHM_GRADIENTS_H_ 9 | #define ALGORITHM_GRADIENTS_H_ 10 | 11 | // Common utility headers ------------- 12 | // Standard C/C++ library 13 | #include"../../common/includes.h" 14 | 15 | // Data Objects 16 | #include"../../common/types.h" 17 | 18 | // Constants 19 | #include"../../common/Constants/MarchingCubesTables.h" 20 | 21 | template 22 | static void computeGradient(unsigned xidx, unsigned yidx, unsigned zidx, const Image3DReader*, T grad[3]); 23 | 24 | template 25 | void computeAllGradients(unsigned &xidx, unsigned &yidx, unsigned &zidx, const Image3DReader*, T (& grad)[8][3]); 26 | 27 | #endif /* ALGORITHM_GRADIENTS_H_ */ 28 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(srcs 2 | Data_Obj/Image3D.cpp 3 | Data_Obj/TriangleMesh.cpp 4 | Data_Obj/Triplet.cpp 5 | 6 | IO/LoadBigImage.cpp 7 | IO/LoadImage3DMPI.cpp 8 | 9 | Reporting/Timer.cpp 10 | Reporting/YAML_Doc.cpp 11 | Reporting/YAML_Element.cpp 12 | 13 | Constants/MarchingCubesTables.cpp 14 | Constants/TypeInfo.cpp 15 | 16 | User_Interface/UI.cpp 17 | 18 | Algorithm/BlockMarchFunctor.cpp 19 | Algorithm/EdgeIndexer.cpp 20 | Algorithm/gradients.cpp 21 | Algorithm/Image3DReader.cpp 22 | Algorithm/MarchAlgorithm.cpp 23 | 24 | GeneralContext/GeneralContext.cpp 25 | ) 26 | 27 | add_library(mantevo_marching_cubes_common 28 | ${srcs} 29 | ) 30 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/Constants/MarchingCubesTables.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MarchingCubesTables.h 3 | * 4 | * Created on: Jul 10, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef ALGORITHM_MARCHINGCUBESTABLES_H_ 9 | #define ALGORITHM_MARCHINGCUBESTABLES_H_ 10 | 11 | // Common utility headers ------------- 12 | // Standard C/C++ library 13 | #include"../includes.h" 14 | 15 | static const int caseMask[] = { 1, 2, 4, 8, 16, 32, 64, 128 }; 16 | 17 | class MarchingCubesTables { 18 | public: 19 | static const int* getEdgeVertices(int edgeId); 20 | static const int* getCaseTrianglesEdges(int caseId); 21 | static unsigned getNumberOfTriangles(int caseId); 22 | 23 | private: 24 | static const int edgeVertices[12][2]; 25 | static const int caseTrianglesEdges[256][16]; 26 | static const unsigned numberOfTriangles[256]; 27 | }; 28 | 29 | inline const int* MarchingCubesTables::getEdgeVertices(int edgeId) { 30 | return edgeVertices[edgeId]; 31 | } 32 | 33 | inline const int* MarchingCubesTables::getCaseTrianglesEdges(int caseId) { 34 | return caseTrianglesEdges[caseId]; 35 | } 36 | 37 | inline unsigned MarchingCubesTables::getNumberOfTriangles(int caseId) { 38 | return numberOfTriangles[caseId]; 39 | } 40 | 41 | #endif /* ALGORITHM_MARCHINGCUBESTABLES_H_ */ 42 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/Constants/TypeInfo.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * TypeInfo.cpp 3 | * 4 | * Created on: Aug 21, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #include"../includes.h" 9 | 10 | #include"./TypeInfo.h" 11 | 12 | TypeInfo::TypeId getTypeId(const char *name) { 13 | std::string nm(name); 14 | for (int i = 1; i < TypeInfo::NUM_TYPES; ++i) { 15 | if (nm == names[i]) { 16 | return TypeInfo::TypeId(i); 17 | } 18 | } 19 | return TypeInfo::ID_UNKNOWN; 20 | } 21 | 22 | TypeInfo::TypeInfo(TypeId inId) : 23 | id(inId) { 24 | } 25 | 26 | TypeInfo::TypeInfo(const char * typeName) : id(getTypeId(typeName)) { 27 | } 28 | 29 | TypeInfo::TypeId TypeInfo::getId() const { 30 | return id; 31 | } 32 | 33 | const char* TypeInfo::name() const { 34 | return names[id]; 35 | } 36 | 37 | size_t TypeInfo::size() const { 38 | return sizes[id]; 39 | } 40 | 41 | 42 | template 43 | TypeInfo createTemplateTypeInfo() { 44 | return TypeInfo(TypeInfo::ID_UNKNOWN); 45 | } 46 | 47 | template<> 48 | TypeInfo createTemplateTypeInfo() { 49 | return TypeInfo(TypeInfo::ID_CHAR); 50 | } 51 | 52 | template<> 53 | TypeInfo createTemplateTypeInfo() { 54 | return TypeInfo(TypeInfo::ID_SHORT); 55 | } 56 | 57 | template<> 58 | TypeInfo createTemplateTypeInfo() { 59 | return TypeInfo(TypeInfo::ID_SHORT); 60 | } 61 | 62 | template<> 63 | TypeInfo createTemplateTypeInfo() { 64 | return TypeInfo(TypeInfo::ID_INT); 65 | } 66 | 67 | template<> 68 | TypeInfo createTemplateTypeInfo() { 69 | return TypeInfo(TypeInfo::ID_FLOAT); 70 | } 71 | 72 | template<> 73 | TypeInfo createTemplateTypeInfo() { 74 | return TypeInfo(TypeInfo::ID_DOUBLE); 75 | } 76 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/Constants/TypeInfo.h: -------------------------------------------------------------------------------- 1 | #ifndef __TypeInfo_h 2 | #define __TypeInfo_h 3 | 4 | #include 5 | 6 | static const char *names[] = { "unknown", "char", "short", "unsigned_short", 7 | "int", "float", "double" }; 8 | static const size_t sizes[] = { 0, 1, 2, 2, 4, 4, 8 }; 9 | 10 | class TypeInfo { 11 | public: 12 | enum TypeId { 13 | ID_UNKNOWN = 0, 14 | ID_CHAR, 15 | ID_SHORT, 16 | ID_USHORT, 17 | ID_INT, 18 | ID_FLOAT, 19 | ID_DOUBLE, 20 | NUM_TYPES 21 | }; 22 | 23 | TypeInfo(TypeId); 24 | TypeInfo(const char *typeName); 25 | 26 | TypeId getId() const; 27 | const char* name() const; 28 | size_t size() const; 29 | 30 | private: 31 | TypeId id; 32 | }; 33 | 34 | template 35 | TypeInfo createTemplateTypeInfo(); 36 | 37 | template<> 38 | TypeInfo createTemplateTypeInfo(); 39 | 40 | template<> 41 | TypeInfo createTemplateTypeInfo(); 42 | template<> 43 | TypeInfo createTemplateTypeInfo(); 44 | 45 | template<> 46 | TypeInfo createTemplateTypeInfo(); 47 | 48 | template<> 49 | TypeInfo createTemplateTypeInfo(); 50 | 51 | template<> 52 | TypeInfo createTemplateTypeInfo(); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/Data_Obj/Image3D.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Image3D.cpp 3 | * 4 | * Created on: Jul 6, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #include"Image3D.h" 9 | 10 | template 11 | Image3D::Image3D() : 12 | npoints(0), data(0) { 13 | 14 | dim[0] = dim[1] = dim[2] = 0; 15 | spacing[0] = spacing[1] = spacing[2] = 0.0; 16 | origin[0] = origin[1] = origin[2] = 0.0; 17 | isMPIdataBlock=false; 18 | MPIorigin[0]=MPIorigin[1]=MPIorigin[2]=0; 19 | sliceSize=0; 20 | } 21 | 22 | template 23 | Image3D::~Image3D() { 24 | delete[] this->data; 25 | } 26 | 27 | template 28 | void Image3D::setDimension(unsigned xdim, unsigned ydim, unsigned zdim) { 29 | this->dim[0] = xdim; 30 | this->dim[1] = ydim; 31 | this->dim[2] = zdim; 32 | sliceSize=dim[0]*dim[1]; 33 | } 34 | 35 | template 36 | void Image3D::setMPIorigin(unsigned xorg, unsigned yorg, unsigned zorg) { 37 | this->MPIorigin[0]=xorg; 38 | this->MPIorigin[1]=yorg; 39 | this->MPIorigin[2]=zorg; 40 | } 41 | 42 | template 43 | void Image3D::setSpacing(T xspc, T yspc, T zspc) { 44 | this->spacing[0] = xspc; 45 | this->spacing[1] = yspc; 46 | this->spacing[2] = zspc; 47 | } 48 | 49 | template 50 | void Image3D::setOrigin(T x, T y, T z) { 51 | this->origin[0] = x; 52 | this->origin[1] = y; 53 | this->origin[2] = z; 54 | } 55 | 56 | template 57 | void Image3D::setToMPIdataBlock(void) { 58 | isMPIdataBlock=true; 59 | } 60 | 61 | template 62 | void Image3D::allocate() { 63 | this->npoints = dim[0] * dim[1] * dim[2]; 64 | delete[] this->data; 65 | this->data = new T[npoints]; 66 | } 67 | 68 | template 69 | T* Image3D::getData() { 70 | return this->data; 71 | } 72 | 73 | template 74 | const unsigned* Image3D::getDimension() const { 75 | return this->dim; 76 | } 77 | 78 | template 79 | unsigned Image3D::getNumberOfPoints() const { 80 | return this->npoints; 81 | } 82 | 83 | template 84 | const T* Image3D::getSpacing() const { 85 | return this->spacing; 86 | } 87 | 88 | template 89 | const T* Image3D::getOrigin() const { 90 | return this->origin; 91 | } 92 | 93 | template 94 | const T* Image3D::getData() const { 95 | CLOG(logWARNING) << "Image3D::getData() call"; 96 | CLOG(logWARNING) << "Will be deleting this function soon"; 97 | return this->data; 98 | } 99 | 100 | #include"../Algorithm/Image3DReader.h" 101 | // Must instantiate class for separate compilation 102 | template class Image3D ; 103 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/Data_Obj/Image3D.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Image3D.h 3 | * 4 | * Created on: Jul 6, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef DATA_OBJ_IMAGE3D_H_ 9 | #define DATA_OBJ_IMAGE3D_H_ 10 | 11 | #include"../includes.h" 12 | 13 | // Reporting Headers 14 | #include"../Reporting/YAML_Element.hpp" 15 | #include"../Reporting/YAML_Doc.hpp" 16 | #include"../Reporting/Log.h" 17 | 18 | template class Image3DReader; 19 | 20 | template 21 | class Image3D { 22 | public: 23 | Image3D(); 24 | virtual ~Image3D(); 25 | 26 | void setDimension(unsigned, unsigned, unsigned); 27 | void setMPIorigin(unsigned, unsigned, unsigned); 28 | void setSpacing(T, T, T); 29 | void setOrigin(T, T, T); 30 | void setToMPIdataBlock(void); 31 | 32 | void allocate(); 33 | T *getData(); 34 | 35 | const unsigned* getDimension() const; 36 | unsigned getNumberOfPoints() const; 37 | const T* getSpacing() const; 38 | const T* getOrigin() const; 39 | const T* getData() const; 40 | 41 | // void report(YAML_Doc &) const; 42 | 43 | template friend class Image3DReader; 44 | // void setImage3DOutputBuffers(const unsigned, const unsigned,const unsigned); 45 | // void getVertexValues(T *,unsigned,unsigned); 46 | // 47 | // void getValsForGradient(T (& x)[3][2], const unsigned, const unsigned, const unsigned) const; 48 | 49 | private: 50 | // Prevent object copying (would cost too much memory 51 | Image3D(const Image3D&); // no implementation 52 | Image3D& operator=(const Image3D&); // no implementation 53 | 54 | // ===== Image data ========================= 55 | unsigned dim[3]; 56 | unsigned sliceSize; 57 | unsigned npoints; 58 | T spacing[3]; 59 | T origin[3]; 60 | T *data; 61 | 62 | bool isMPIdataBlock; 63 | unsigned MPIorigin[3]; 64 | 65 | // /* ===== Reading image object =============== 66 | // * Collection of buffers to allow the Image3D 67 | // * object to read itself efficiently. 68 | // ==========================================*/ 69 | // unsigned bufferIdx; 70 | // /* 71 | // * 4 buffers improve cache efficiency 72 | // * this speeds up run time significantly 73 | // */ 74 | // const T *X1buffer; 75 | // const T *X2buffer; 76 | // const T *X3buffer; 77 | // const T *X4buffer; 78 | // 79 | // /* ===== Reading image object =============== 80 | // * Collection of functions to allow the Image3D 81 | // * object to read itself efficiently. 82 | // ==========================================*/ 83 | }; 84 | 85 | #endif /* DATA_OBJ_IMAGE3D_H_ */ 86 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/Data_Obj/TriangleMesh.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TriangleMesh.h 3 | * 4 | * Created on: Jul 7, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef DATA_OBJ_TRIANGLEMESH_H_ 9 | #define DATA_OBJ_TRIANGLEMESH_H_ 10 | 11 | #include"../includes.h" 12 | 13 | #include"./Triplet.h" 14 | #include"../Reporting/Log.h" 15 | 16 | template 17 | class TriangleMesh { 18 | 19 | typedef Triplet Point3d; 20 | typedef Triplet Vector3d; 21 | typedef Triplet Triangle; 22 | public: 23 | TriangleMesh(); 24 | TriangleMesh(TriangleMesh&); 25 | virtual ~TriangleMesh(); 26 | 27 | // Data member interface: write 28 | void allocate(unsigned); 29 | 30 | void addPoint(T *); 31 | void addPoint(T,T,T); 32 | void addPoint(Point3d); 33 | 34 | void addNormal(T *); 35 | void addNormal(T,T,T); 36 | void addNormal(Vector3d); 37 | 38 | void addTriangle(unsigned *); 39 | void addTriangle(unsigned,unsigned,unsigned); 40 | void addTriangle(Triangle); 41 | 42 | void setPoint(unsigned,const T *); 43 | void setNormal(unsigned,const T *); 44 | void resetTheMesh(void); 45 | 46 | // Marching Cubes 47 | 48 | // Combine 2 meshes 49 | TriangleMesh& operator+=(TriangleMesh&); 50 | 51 | // Data member interface: read 52 | const T* getPointPosition(unsigned) const; 53 | void getPointPosition(unsigned,Point3d &) const; 54 | const T* getNormalVector(unsigned) const; 55 | const unsigned* getTriangleIndices(unsigned) const; 56 | 57 | // Get info on the mesh 58 | unsigned numberOfVertices() const; 59 | unsigned numberOfTriangles() const; 60 | 61 | // This function is not a member b/c we keep I/O separate 62 | template friend void saveTriangleMesh(const TriangleMesh *, const char *); 63 | 64 | private: 65 | // Prevent object copying 66 | TriangleMesh(const TriangleMesh&); // no implementation 67 | TriangleMesh& operator=(const TriangleMesh&); // no implementation 68 | 69 | std::vector points; 70 | std::vector normals; 71 | std::vector indices; 72 | }; 73 | 74 | #endif /* DATA_OBJ_TRIANGLEMESH_H_ */ 75 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/Data_Obj/Triplet.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Triplet.h 3 | * 4 | * Created on: Jul 14, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | /* 9 | * Triplet Class 10 | * Purpose: Store triplets of coordinates or indices 11 | * 12 | * Usage: 3-dimensional points: 13 | * Triplet point; 14 | * 15 | * Triangle point index: 16 | * Triplet triangle; 17 | */ 18 | 19 | #ifndef DATA_OBJ_TRIPLET_H_ 20 | #define DATA_OBJ_TRIPLET_H_ 21 | 22 | // External includes 23 | #include"../includes.h" 24 | 25 | // Reporting Headers 26 | #include"../Reporting/Log.h" 27 | 28 | template 29 | class Triplet { 30 | public: 31 | // Constructor/Destructors 32 | Triplet(); 33 | Triplet(const T, const T, const T); // Recommended 34 | Triplet(const T *); 35 | virtual ~Triplet(); 36 | 37 | // Assignment 38 | void setCoordinates(const T, const T, const T); // Recommended 39 | void setCoordinates(const T*); // Risky b/c no bounds check 40 | void operator=(const T*); 41 | void operator=(const Triplet&); 42 | Triplet& operator+=(const T); 43 | Triplet& operator+=(const Triplet); 44 | 45 | // Comparison 46 | bool operator==(const Triplet &) const; 47 | bool operator==(const T*) const; 48 | bool operator!=(const Triplet &) const; 49 | bool operator!=(const T*) const; 50 | bool operator <(const Triplet& rhs) const 51 | { 52 | return coordinates[0] < rhs.coordinates[0]; 53 | } 54 | 55 | // Coordinate retrieval 56 | T const* getCoordinates(void) const; 57 | T const& operator[](int idx) const { return coordinates[idx]; }; 58 | template friend std::ostream& operator<<(std::ostream&, const Triplet&); 59 | 60 | private: 61 | // Need an array because std::array is a C++11 feature 62 | T coordinates[3]; 63 | }; 64 | 65 | #endif /* DATA_OBJ_TRIPLET_H_ */ 66 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/Data_Obj/tests/TriangleMesh_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * TriangleMesh_test.cpp 3 | * 4 | * Created on: Jul 16, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | 9 | /* 10 | * Tests all passed 11 | * Ran with 12 | * g++ -omeshtest -lboost_unit_test_framework TriangleMesh_test.cpp 13 | */ 14 | #define BOOST_TEST_DYN_LINK 15 | #define BOOST_TEST_MODULE tritest 16 | #include 17 | #include"Triplet.h" 18 | #include"Triplet.cpp" // Bad practice to include .cpp 19 | // is necessary for compiling tests though 20 | #include"TriangleMesh.h" 21 | #include"TriangleMesh.cpp" 22 | 23 | //BOOST_AUTO_TEST_CASE(universeInOrder) 24 | //{ 25 | // TriangleMesh TheMesh; 26 | // float ptA[]={1.1,1.2,1.3}; 27 | // float ptB[]={2.1,2.2,2.3}; 28 | // float norm[]={3.1,3.2,3.3}; 29 | // 30 | // TheMesh.addPoint(ptA); 31 | // TheMesh.addPoint(ptB[0],ptB[1],ptB[2]); 32 | // TheMesh.addNormal(norm); 33 | // 34 | // unsigned idx[]={0,1,2}; 35 | // TheMesh.addTriangle(idx); 36 | // 37 | // Triplet pointA(ptA), pointB(ptB); 38 | // Triplet normA(norm); 39 | // Triplet triangle(idx); 40 | // std::cout << "The mesh indices," << std::endl; 41 | // std::cout << TheMesh.getTriangleIndices(0)[0] << std::endl; 42 | // std::cout << TheMesh.getTriangleIndices(0)[1] << std::endl; 43 | // std::cout << TheMesh.getTriangleIndices(0)[2] << std::endl; 44 | // BOOST_CHECK(pointA == TheMesh.getPointPosition(0)); 45 | // BOOST_CHECK(pointB == TheMesh.getPointPosition(1)); 46 | // BOOST_CHECK(normA == TheMesh.getNormalVector(0)); 47 | // BOOST_CHECK(triangle == TheMesh.getTriangleIndices(0)); 48 | // 49 | // 50 | // BOOST_CHECK(TheMesh); 51 | //} 52 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/Data_Obj/tests/triplet_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * triplet_test.cpp 3 | * 4 | * Created on: Jul 14, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | 9 | /* 10 | * Tests all passed 11 | * Ran with 12 | * g++ -otritest -lboost_unit_test_framework triplet_test.cpp 13 | * 14 | */ 15 | 16 | #define BOOST_TEST_DYN_LINK 17 | #define BOOST_TEST_MODULE tritest 18 | #include 19 | #include"Triplet.h" 20 | #include"Triplet.cpp" // Bad practice to include .cpp 21 | // is necessary for compiling tests though 22 | 23 | BOOST_AUTO_TEST_CASE(universeInOrder) 24 | { 25 | // Assignment array to Triplet 26 | float coords[]={1.2,1.3,1.4}; 27 | float coordsB[]={2.2,2.3,2.4}; 28 | Triplet ptA(coords); 29 | ptA=coordsB; 30 | const float * assignment = ptA.getCoordinates(); 31 | BOOST_CHECK(assignment[0] == coordsB[0]); 32 | BOOST_CHECK(assignment[1] == coordsB[1]); 33 | BOOST_CHECK(assignment[2] == coordsB[2]); 34 | 35 | // Assignment of Triplet to Triplet 36 | Triplet ptB(coords); 37 | ptA=ptB; 38 | assignment = ptA.getCoordinates(); 39 | BOOST_CHECK(assignment[0] == coords[0]); 40 | BOOST_CHECK(assignment[1] == coords[1]); 41 | BOOST_CHECK(assignment[2] == coords[2]); 42 | 43 | // Comparison of two objects 44 | BOOST_CHECK(ptA == ptB); 45 | 46 | // Coordinate retrieval 47 | Triplet pt(1,2,3); 48 | int coordsC[]={1,2,3}; 49 | const int * othercoords = pt.getCoordinates(); 50 | BOOST_CHECK(othercoords[0] == coordsC[0]); 51 | BOOST_CHECK(othercoords[1] == coordsC[1]); 52 | BOOST_CHECK(othercoords[2] == coordsC[2]); 53 | 54 | } 55 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/GeneralContext/GeneralContext.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GeneralContext.cpp 3 | * 4 | * Created on: Aug 17, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #include "GeneralContext.h" 9 | 10 | template 11 | GeneralContext::GeneralContext() : doc("Marching Cubes", "0.1", ".", "yaml_out.yaml") { 12 | _strategy=0; 13 | } 14 | 15 | 16 | template 17 | GeneralContext::GeneralContext(MarchAlgorithm * implementation) : doc("Marching Cubes", "0.1", ".", "yaml_out.yaml") { 18 | _strategy=implementation; 19 | } 20 | 21 | template 22 | GeneralContext::~GeneralContext() { 23 | } 24 | 25 | template 26 | void GeneralContext::setAlgorithm(MarchAlgorithm * implementation) { 27 | _strategy=implementation; 28 | } 29 | 30 | template 31 | void GeneralContext::march(void) { 32 | _strategy->march(*this); 33 | } 34 | 35 | // Must instantiate class for separate compilation 36 | template class GeneralContext; 37 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/GeneralContext/GeneralContext.h: -------------------------------------------------------------------------------- 1 | /* 2 | * GeneralContext.h 3 | * 4 | * Created on: Aug 17, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef GENERALCONTEXT_H_ 9 | #define GENERALCONTEXT_H_ 10 | 11 | #include"../includes.h" 12 | 13 | // Data Object definitions 14 | #include"../Data_Obj/Image3D.h" 15 | #include"../Data_Obj/TriangleMesh.h" 16 | #include"../Data_Obj/Triplet.h" 17 | 18 | #include"../Algorithm/MarchAlgorithm.h" 19 | 20 | template 21 | class GeneralContext { 22 | public: 23 | GeneralContext(); 24 | GeneralContext(MarchAlgorithm *); 25 | virtual ~GeneralContext(); 26 | 27 | void setAlgorithm(MarchAlgorithm *); 28 | 29 | // Data writing methods 30 | Image3D * imgAdr(void) { return &imageIn;}; 31 | 32 | void march(void); 33 | public: 34 | // General/minimal marching cubes runtime data 35 | Image3D imageIn; 36 | unsigned ext[6]; 37 | T isoval; 38 | TriangleMesh mesh; 39 | 40 | // Initialize console log and YAML 41 | YAML_Doc doc; 42 | private: 43 | // Prevent object copying 44 | GeneralContext(const GeneralContext&); // no implementation 45 | GeneralContext& operator=(const GeneralContext&); // no implementation 46 | 47 | MarchAlgorithm *_strategy; 48 | }; 49 | 50 | #endif /* GENERALCONTEXT_H_ */ 51 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/IO/ConvertBuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ConvertBuffer.h 3 | * 4 | * Created on: Jul 6, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef CONVERTBUFFER_H_ 9 | #define CONVERTBUFFER_H_ 10 | 11 | #include"../includes.h" 12 | #include"../Constants/TypeInfo.h" 13 | 14 | // Reporting Headers 15 | #include"../Reporting/IO_errors.h" 16 | #include"../Reporting/Log.h" 17 | 18 | template 19 | inline void flipEndianness(T &val) { 20 | int mid = sizeof(T) / 2; 21 | char *data = reinterpret_cast(&val); 22 | for (int i = 0; i < mid; ++i) { 23 | std::swap(data[i], data[sizeof(T) - i - 1]); 24 | } 25 | } 26 | 27 | template 28 | void convertBuffer(const SrcT *in, size_t nelms, DstT *out) { 29 | for (size_t i = 0; i < nelms; ++i) { 30 | SrcT val = *in++; 31 | flipEndianness(val); 32 | *out++ = static_cast(val); 33 | } 34 | } 35 | 36 | template 37 | void convertBufferWithTypeInfo(const char *in, const TypeInfo &ti, size_t nelms, 38 | T *out) { 39 | switch (ti.getId()) { 40 | case TypeInfo::ID_CHAR: 41 | convertBuffer(in, nelms, out); 42 | break; 43 | case TypeInfo::ID_SHORT: 44 | convertBuffer(reinterpret_cast(in), nelms, out); 45 | break; 46 | case TypeInfo::ID_USHORT: 47 | convertBuffer(reinterpret_cast(in), nelms, out); 48 | break; 49 | case TypeInfo::ID_INT: 50 | convertBuffer(reinterpret_cast(in), nelms, out); 51 | break; 52 | case TypeInfo::ID_FLOAT: 53 | convertBuffer(reinterpret_cast(in), nelms, out); 54 | break; 55 | case TypeInfo::ID_DOUBLE: 56 | convertBuffer(reinterpret_cast(in), nelms, out); 57 | break; 58 | default: 59 | throw no_type("Data type is not supported"); 60 | break; 61 | } 62 | } 63 | 64 | #endif /* CONVERTBUFFER_H_ */ 65 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/IO/LineStream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LineStream.h 3 | * 4 | * Created on: Jul 6, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef LINESTREAM_H_ 9 | #define LINESTREAM_H_ 10 | 11 | class LineStream { 12 | public: 13 | LineStream(std::istream &in); 14 | std::istream& stream(); 15 | 16 | void readline(); 17 | 18 | private: 19 | std::istream ∈ 20 | std::stringstream sstream; 21 | std::string line; 22 | }; 23 | 24 | inline LineStream::LineStream(std::istream &input) : 25 | in(input) { 26 | } 27 | 28 | inline std::istream& LineStream::stream() { 29 | return this->sstream; 30 | } 31 | 32 | inline void LineStream::readline() { 33 | std::getline(this->in, this->line); 34 | this->sstream.clear(); 35 | this->sstream.str(this->line); 36 | this->sstream.seekg(0); 37 | } 38 | 39 | #endif /* LINESTREAM_H_ */ 40 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/IO/LoadBigImage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LoadBigImage.h 3 | * 4 | * Created on: Aug 20, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef IO_LOADIMAGE3DMPI_H_ 9 | #define IO_LOADIMAGE3DMPI_H_ 10 | 11 | #include"../includes.h" 12 | 13 | // I/O headers 14 | #include"../Data_Obj/Image3D.h" 15 | #include"LineStream.h" 16 | #include"ConvertBuffer.h" 17 | 18 | // Reporting Headers 19 | #include"../Reporting/IO_errors.h" 20 | #include"../Reporting/MPI_errors.h" 21 | #include"../Reporting/Log.h" 22 | 23 | static const int N_HEADER_LINES=10; 24 | 25 | template 26 | class LoadBigImage { 27 | public: 28 | LoadBigImage(); 29 | LoadBigImage(LoadBigImage&); 30 | virtual ~LoadBigImage(); 31 | 32 | // File loading members 33 | // General file 34 | void loadHeader(const char *); 35 | void report(YAML_Doc &) const; 36 | // MPI process specific 37 | void setBlockExtent(const unsigned *); 38 | void readEntireVolumeData(Image3D&); 39 | void readBlockData(Image3D&); 40 | // Object member read 41 | const unsigned* getVolumeDimensions(void) const; 42 | unsigned getMaxVoumeDimension(void) const; 43 | unsigned getnVolumePoints(void) const; 44 | const T* getSpacing(void) const; 45 | const T* getOrigin(void) const; 46 | const char* whichFile(void) const { return vtkFile; } 47 | private: 48 | // Private member functions 49 | void streamIgnore(unsigned); 50 | // File reader objects 51 | std::ifstream stream; 52 | LineStream *reader; 53 | const char *vtkFile; 54 | 55 | // general parameters for the image file 56 | unsigned xdimFile,ydimFile,zdimFile; 57 | unsigned fileNpoints; 58 | T spacing[3]; 59 | T origin[3]; 60 | TypeInfo* typeInfo; 61 | 62 | // MPI process specific 63 | bool blockExtentSet; 64 | unsigned blockExtent[6]; 65 | unsigned nPointsInBlock; 66 | unsigned imageDataIdx; 67 | }; 68 | 69 | #endif /* IO_LOADIMAGE3DMPI_H_ */ 70 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/IO/LoadImage3DMPI.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LoadImage3DMPI.h 3 | * 4 | * Created on: Aug 20, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef IO_LOADIMAGE3DMPI_H_ 9 | #define IO_LOADIMAGE3DMPI_H_ 10 | 11 | #include"../includes.h" 12 | 13 | // I/O headers 14 | #include"../Data_Obj/Image3D.h" 15 | #include"LineStream.h" 16 | #include"ConvertBuffer.h" 17 | 18 | // Reporting Headers 19 | #include"../Reporting/IO_errors.h" 20 | #include"../Reporting/MPI_errors.h" 21 | #include"../Reporting/Log.h" 22 | 23 | static const int N_HEADER_LINES=10; 24 | 25 | template 26 | class LoadImage3DMPI { 27 | public: 28 | LoadImage3DMPI(); 29 | LoadImage3DMPI(LoadImage3DMPI&); 30 | virtual ~LoadImage3DMPI(); 31 | 32 | // File loading members 33 | void setSperateData(const char *); 34 | // General file 35 | void loadHeader(const char *); 36 | void report(YAML_Doc &) const; 37 | // MPI process specific 38 | void setBlockExtent(const unsigned *); 39 | void readEntireVolumeData(Image3D&); 40 | void readBlockData(Image3D&); 41 | // Object member read 42 | unsigned const* getVolumeDimensions(void); 43 | unsigned getMaxVoumeDimension(void) const; 44 | unsigned getnVolumePoints(void) const; 45 | const T* getSpacing(void) const; 46 | const T* getOrigin(void) const; 47 | const char* whichFile(void) const { return vtkFile; } 48 | private: 49 | // Private member functions 50 | void streamIgnore(unsigned); 51 | // File reader objects 52 | std::ifstream stream; 53 | LineStream *reader; 54 | const char *vtkFile; 55 | const char *vtkDataFile; 56 | bool seperateData; 57 | 58 | // general parameters for the image file 59 | unsigned xdimFile,ydimFile,zdimFile; 60 | unsigned dimsArray[3]; 61 | unsigned fileNpoints; 62 | T spacing[3]; 63 | T origin[3]; 64 | TypeInfo* typeInfo; 65 | 66 | // MPI process specific 67 | bool blockExtentSet; 68 | unsigned blockExtent[6]; 69 | unsigned nPointsInBlock; 70 | unsigned imageDataIdx; 71 | }; 72 | 73 | #endif /* IO_LOADIMAGE3DMPI_H_ */ 74 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/IO/LoadImage3DMPI_test.cxx: -------------------------------------------------------------------------------- 1 | /* 2 | * LoadImage3DMPI_test.cxx 3 | * 4 | * Created on: Aug 20, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | /* 9 | * LoadImage3DMPI_test.cpp 10 | * 11 | * Created on: Jul 16, 2015 12 | * Author: sjmunn 13 | */ 14 | 15 | /* 16 | * Tests all passed 17 | * Ran with 18 | * export LD_LIBRARY_PATH=/usr/lib64 19 | * g++ -std=c++0x -oiotest -lboost_unit_test_framework LoadImage3DMPI_test.cxx 20 | */ 21 | #define BOOST_TEST_DYN_LINK 22 | #define BOOST_TEST_MODULE tritest 23 | #include 24 | 25 | #include"LoadImage3DMPI.h" 26 | #include"LoadImage3DMPI.cpp" // Bad practice to include .cpp 27 | // is necessary for compiling tests though 28 | 29 | #include"../Data_Obj/Image3D.h" 30 | #include"../Data_Obj/Image3D.cpp" 31 | #include"../Reporting/YAML_Doc.hpp" 32 | #include"../Reporting/YAML_Doc.cpp" 33 | #include"../Reporting/YAML_Element.hpp" 34 | #include"../Reporting/YAML_Element.cpp" 35 | 36 | BOOST_AUTO_TEST_CASE(readingHeader) { 37 | LoadImage3DMPI headerInfo; 38 | headerInfo.loadHeader("../../Data/ctmini.vtk"); 39 | const unsigned *dims = headerInfo.getVolumeDimensions(); 40 | BOOST_CHECK(dims[0] == 3); 41 | BOOST_CHECK(dims[1] == 3); 42 | BOOST_CHECK(dims[2] == 3); 43 | BOOST_CHECK(headerInfo.getnVolumePoints() == 27); 44 | 45 | } 46 | 47 | BOOST_AUTO_TEST_CASE(readingFirstBlock) { 48 | BOOST_TEST_CHECKPOINT("Getting header info"); 49 | LoadImage3DMPI headerInfo; 50 | headerInfo.loadHeader("../../Data/ctmini.vtk"); 51 | const unsigned *dims = headerInfo.getVolumeDimensions(); 52 | 53 | BOOST_TEST_CHECKPOINT("Initializing new reader object"); 54 | LoadImage3DMPI firstBlock(headerInfo); 55 | BOOST_TEST_CHECKPOINT("firstBlock is initialized to binary data in the file"); 56 | unsigned extent[6] = { 0, 0, 0, 0, 0, 0 }; 57 | firstBlock.setBlockExtent(extent); 58 | Image3D imageVol; 59 | BOOST_TEST_CHECKPOINT("Read the image block"); 60 | firstBlock.readBlockData(imageVol); 61 | 62 | // get the point from imageVol 63 | float_t expected[8]={100,100,100,100,100,100,5000,5000}; 64 | const float_t *buffer; 65 | buffer = imageVol.getData(); 66 | for (int iPoint=0;iPoint<8;++iPoint) { 67 | BOOST_CHECK(buffer[iPoint] == expected[iPoint]); 68 | } 69 | } 70 | 71 | BOOST_AUTO_TEST_CASE(readingLargerBlock) { 72 | BOOST_TEST_CHECKPOINT("Getting header info"); 73 | LoadImage3DMPI headerInfo; 74 | headerInfo.loadHeader("../../Data/ctmini.vtk"); 75 | const unsigned *dims = headerInfo.getVolumeDimensions(); 76 | 77 | BOOST_TEST_CHECKPOINT("Initializing new reader object"); 78 | LoadImage3DMPI firstBlock(headerInfo); 79 | BOOST_TEST_CHECKPOINT("firstBlock is initialized to binary data in the file"); 80 | unsigned extent[6] = { 0, 1, 0, 1, 0, 0 }; 81 | firstBlock.setBlockExtent(extent); 82 | Image3D imageVol; 83 | BOOST_TEST_CHECKPOINT("Read the image block"); 84 | firstBlock.readBlockData(imageVol); 85 | 86 | // get the point from imageVol 87 | const float_t *buffer; 88 | buffer = imageVol.getData(); 89 | for (int iPoint=0;iPoint<18;++iPoint) { 90 | std::cout << "buffer val is: " << buffer[iPoint] << std::endl; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/IO/SaveTriangleMesh.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SaveTriangleMesh.h 3 | * 4 | * Created on: Jul 10, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef SAVETRIANGLEMESH_H_ 9 | #define SAVETRIANGLEMESH_H_ 10 | 11 | #include"../includes.h" 12 | 13 | #include "ConvertBuffer.h" 14 | 15 | // Data Objects 16 | #include"../types.h" 17 | 18 | // This Function is a friend of the Triangle Mesh class and has access to private members of that class 19 | template 20 | void saveTriangleMesh(const TriangleMesh *mesh, const char * vtkFileName) { 21 | std::ofstream stream; 22 | stream.open(vtkFileName); 23 | int spacialDimensions = 3; 24 | 25 | unsigned nverts = mesh->numberOfVertices(); 26 | unsigned ntriangles = mesh->numberOfTriangles(); 27 | TypeInfo ti = createTemplateTypeInfo(); 28 | 29 | size_t bufsize = 0; 30 | std::vector wbuff; 31 | 32 | stream << "# vtk DataFile Version 3.0" << std::endl; 33 | stream << "Isosurface Mesh" << std::endl; 34 | stream << "BINARY" << std::endl; 35 | stream << "DATASET POLYDATA" << std::endl; 36 | 37 | bufsize = mesh->points.size() * spacialDimensions * sizeof(T); 38 | wbuff.resize(bufsize); 39 | 40 | // Writing points data 41 | stream << "POINTS " << nverts << " " << ti.name() << std::endl; 42 | 43 | T *bufPointer = reinterpret_cast(&wbuff[0]); 44 | 45 | typedef Triplet Point3d; 46 | for (typename std::vector::const_iterator it=mesh->points.begin(); it != mesh->points.end(); ++it) { 47 | for (int iCoordinate = 0; iCoordinate < 3; ++iCoordinate) { 48 | *bufPointer = (*it)[iCoordinate]; 49 | flipEndianness(*bufPointer++); 50 | } 51 | } 52 | 53 | stream.write(&wbuff[0], wbuff.size()); 54 | stream << std::endl; 55 | 56 | // Writing triangle indices 57 | 58 | bufsize = ntriangles * 4 * sizeof(unsigned); 59 | wbuff.resize(bufsize); 60 | unsigned *ind = reinterpret_cast(&wbuff[0]); 61 | 62 | typedef Triplet Triangle; 63 | for (typename std::vector::const_iterator it=mesh->indices.begin(); it != mesh->indices.end(); ++it) { 64 | *ind = 3; 65 | flipEndianness(*ind++); 66 | for (int j = 0; j < 3; ++j) { 67 | *ind = (*it)[j]; 68 | flipEndianness(*ind++); 69 | } 70 | } 71 | 72 | stream << "POLYGONS " << ntriangles << " " << ntriangles * 4 << std::endl; 73 | stream.write(&wbuff[0], wbuff.size()); 74 | stream << std::endl; 75 | 76 | bufsize = mesh->normals.size() * spacialDimensions * sizeof(T); 77 | wbuff.resize(bufsize); 78 | bufPointer = reinterpret_cast(&wbuff[0]); 79 | 80 | for (typename std::vector::const_iterator it=mesh->normals.begin(); it != mesh->normals.end(); ++it) { 81 | for (int iCoordinate = 0; iCoordinate < 3; ++iCoordinate) { 82 | *bufPointer = (*it)[iCoordinate]; 83 | flipEndianness(*bufPointer++); 84 | } 85 | } 86 | 87 | stream << "POINT_DATA " << nverts << std::endl; 88 | stream << "NORMALS Normals " << ti.name() << std::endl; 89 | stream.write(&wbuff[0], wbuff.size()); 90 | stream << std::endl; 91 | 92 | stream.close(); 93 | } 94 | 95 | #endif /* SAVETRIANGLEMESH_H_ */ 96 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/IO/iotest: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sandialabs/miniIsosurface/be51bb54e553e357a50cd95fce2fe9a5798993e4/marchingCubes/obsolete/common/IO/iotest -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/Makefile: -------------------------------------------------------------------------------- 1 | # ----------------------------------------------- 2 | # Mantevo Marching Cubes Utility Objects 3 | # 4 | # Author: sjmunn@sandia.gov 5 | # Date : 2015-07-31 6 | # 7 | # Changelog : 8 | # 2015-07-31 - created 9 | # ----------------------------------------------- 10 | 11 | # ========== Macros ============================= 12 | 13 | # Compiler and flags 14 | CC = g++ 15 | #CXXFLAGS = -O2 -fopenmp -lprofiler -std=c++0x 16 | CXXFLAGS = -O2 -lrt -std=c++0x 17 | #CXXFLAGS = -O0 -g -Wall -Wconversion -lrt -std=c++0x 18 | 19 | # Source and build directories 20 | SRCDIRS = Data_Obj IO Reporting Constants User_Interface Algorithm GeneralContext 21 | BUILD_DIRECTORY = build 22 | BUILDDIR = $(BUILD_DIRECTORY) 23 | 24 | # Get source code files and generate object names 25 | SOURCES := $(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.cpp)) 26 | OBJECTS := $(addprefix $(BUILDDIR)/,$(notdir $(SOURCES:.cpp=.o))) 27 | 28 | # ========== Compiler Rules ===================== 29 | 30 | # Linker commands 31 | 32 | all: $(OBJECTS) 33 | @echo "All utility objects have been compiled"; 34 | 35 | # General purpose object compiler 36 | $(BUILDDIR)/%.o: ./*/%.cpp 37 | @mkdir -p $(BUILDDIR); 38 | @echo "Compiling "$@; 39 | @$(CC) $(CXXFLAGS) -c $< -o $@; 40 | 41 | # ========== Cleanup Rules ====================== 42 | 43 | .PHONEY: clean 44 | clean: 45 | rm -f $(BUILDDIR)/*.o; 46 | 47 | .PHONEY: clean_run_data 48 | clean_run_data: 49 | rm -f yaml_out.*; 50 | rm -f callgrind.*; 51 | 52 | .PHONEY: deepclean 53 | deepclean: clean clean_run_data 54 | rm -rf $(BUILDDIR); 55 | 56 | # ========== Debug Rules ======================== 57 | 58 | debug: 59 | @echo "Using compiler: " 60 | @echo $(CC) 61 | @echo "With flags: " 62 | @echo $(CXXFLAGS) 63 | @echo "Source code directories: " 64 | @echo $(SRCDIRS); 65 | @echo "Source code files: " 66 | @echo $(SOURCES); 67 | @echo "Object files: " 68 | @echo $(OBJECTS); 69 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/Reporting/IO_errors.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IO_errors.h 3 | * 4 | * Created on: Jul 6, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef IO_ERRORS_H_ 9 | #define IO_ERRORS_H_ 10 | 11 | #include"../includes.h" 12 | 13 | #include"Log.h" 14 | 15 | class file_not_found: public std::exception { 16 | public: 17 | file_not_found(const char* const inFileName) : 18 | fileName(inFileName) { 19 | 20 | CLOG(logERROR) << "File not found error"; 21 | CLOG(logERROR) << "Given Path: " << fileName; 22 | CLOG(logERROR) << "In linux, type pwd [Enter] to get your current directory"; 23 | CLOG(logERROR) << "The path should be specified relative to the current directory"; 24 | } 25 | 26 | private: 27 | const char* const fileName; 28 | }; 29 | 30 | class object_not_sorted: public std::exception { 31 | public: 32 | object_not_sorted(const char* const inObjectName) : 33 | objectName(inObjectName) { 34 | 35 | CLOG(logERROR) << "The MapReverse object is not sorted"; 36 | CLOG(logERROR) << "Do not call MapReverse::getNewIndices if the object is not sorted"; 37 | } 38 | 39 | private: 40 | const char* const objectName; 41 | }; 42 | 43 | class bad_format: public std::exception { 44 | public: 45 | bad_format(const char* const inMessage) : 46 | message(inMessage) { 47 | CLOG(logERROR) << "Bad format error with message: "; 48 | CLOG(logERROR) << message; 49 | } 50 | 51 | private: 52 | const char* const message; 53 | }; 54 | 55 | class no_type: public std::exception { 56 | public: 57 | no_type(const char* const inMessage) : 58 | message(inMessage) { 59 | CLOG(logERROR) << "Type not defined error with message: "; 60 | CLOG(logERROR) << message; 61 | } 62 | 63 | private: 64 | const char* const message; 65 | }; 66 | 67 | class file_too_large: public std::exception { 68 | public: 69 | file_too_large(const unsigned inMessage) : 70 | message(inMessage) { 71 | 72 | CLOG(logERROR) << "Step by Step debugging is active"; 73 | CLOG(logERROR) << "Only image files up to 1000 points are accepted"; 74 | CLOG(logERROR) << "The file specified has too many data points"; 75 | CLOG(logERROR) << "Number of points in file: " << message; 76 | } 77 | 78 | private: 79 | const unsigned message; 80 | }; 81 | 82 | #endif /* IO_ERRORS_H_ */ 83 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/Reporting/MPI_errors.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MPI_erros.h 3 | * 4 | * Created on: Aug 20, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef REPORTING_MPI_ERRORS_H_ 9 | #define REPORTING_MPI_ERRORS_H_ 10 | 11 | #include"../includes.h" 12 | 13 | #include"Log.h" 14 | 15 | /* 16 | * LoadImage3DMPI errors 17 | */ 18 | class zero_dimensions: public std::exception { 19 | public: 20 | zero_dimensions(const char* const inMessage) : 21 | message(inMessage) { 22 | 23 | CLOG(logERROR) << "When initializing LoadImage3DMPI object A from another LoadImage3DMPI object B,"; 24 | CLOG(logERROR) << "argument B was found to have zero dimensions."; 25 | CLOG(logERROR) << "Either B did not yet read its file's header"; 26 | CLOG(logERROR) << "or the file has not actual image volume data."; 27 | } 28 | 29 | private: 30 | const char* const message; 31 | }; 32 | 33 | class block_extent_not_set: public std::exception { 34 | public: 35 | block_extent_not_set(const char* const inMessage) : 36 | message(inMessage) { 37 | 38 | CLOG(logERROR) << "Cannot call readBlockData() before setting the block extent via setBlockExtent()"; 39 | } 40 | 41 | private: 42 | const char* const message; 43 | }; 44 | 45 | class impossible_extent: public std::exception { 46 | public: 47 | impossible_extent(const char* const inMessage) : 48 | message(inMessage) { 49 | 50 | CLOG(logERROR) << "In LoadImage3D setBlockExtent() member function,"; 51 | CLOG(logERROR) << message; 52 | } 53 | 54 | private: 55 | const char* const message; 56 | }; 57 | 58 | 59 | 60 | #endif /* REPORTING_MPI_ERRORS_H_ */ 61 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/Reporting/RunTime_errors.h: -------------------------------------------------------------------------------- 1 | /* 2 | * RunTime_errors.h 3 | * 4 | * Created on: Jul 27, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef REPORTING_RUNTIME_ERRORS_H_ 9 | #define REPORTING_RUNTIME_ERRORS_H_ 10 | 11 | #include"../includes.h" 12 | 13 | #include"Log.h" 14 | 15 | class wrong_arguments: public std::exception { 16 | public: 17 | wrong_arguments(const int inArgc) : 18 | argc(inArgc) { 19 | 20 | CLOG(logERROR) << "Wrong number of arguments"; 21 | CLOG(logERROR) << "Usage:"; 22 | CLOG(logERROR) << "MarchingCubes in_image.vtk out_poly.vtk isoval"; 23 | CLOG(logERROR) << "OR"; 24 | CLOG(logERROR) << "MarchingCubes in_image_header in_image_data out_poly.vtk isoval"; 25 | } 26 | 27 | private: 28 | const int argc; 29 | }; 30 | 31 | class implementation_not_supported: public std::exception { 32 | public: 33 | implementation_not_supported(const char* const inImplementationID) : 34 | implementationID(inImplementationID) { 35 | 36 | CLOG(logERROR) << "This implementation is not supported"; 37 | CLOG(logERROR) << "Given implementation ID: " << implementationID; 38 | CLOG(logERROR) << "Try a different make rule when building MarchingCubes"; 39 | } 40 | 41 | private: 42 | const char* const implementationID; 43 | }; 44 | 45 | class too_many_edges: public std::exception { 46 | public: 47 | too_many_edges(const unsigned inNedges, const unsigned inNedgesAllowed) : 48 | nEdges(inNedges), nEdgesAllowed(inNedgesAllowed) { 49 | 50 | CLOG(logERROR) << "There are too many edges in this mesh for display"; 51 | CLOG(logERROR) << "Number of edges in mesh: " << nEdges; 52 | CLOG(logERROR) << "Allowed number of edges: " << nEdges; 53 | } 54 | 55 | private: 56 | unsigned nEdges, nEdgesAllowed; 57 | }; 58 | 59 | #endif /* REPORTING_RUNTIME_ERRORS_H_ */ 60 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/Reporting/Timer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Timer.cpp 3 | * 4 | * Created on: Jul 17, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #include "Timer.h" 9 | 10 | Timer::Timer() { 11 | start(); 12 | } 13 | 14 | void Timer::getCurrentTimeValues(TimeValue_t &ticksCPU, 15 | TimeValue_t &wallSeconds, 16 | TimeValue_t &wallNanoseconds) const { 17 | ticksCPU = clock(); 18 | 19 | #if (_POSIX_TIMERS > 0) && (_POSIX_MONOTONIC_CLOCK > 0) 20 | struct timespec currentTime; 21 | clock_gettime(CLOCK_MONOTONIC, ¤tTime); 22 | wallSeconds = currentTime.tv_sec; 23 | wallNanoseconds = currentTime.tv_nsec; 24 | #else 25 | struct timeval currentTime; 26 | gettimeofday(¤tTime, NULL); 27 | wallSeconds = currentTime.tv_sec; 28 | wallNanoseconds = currentTime.tv_usec * 1000; 29 | #endif 30 | } 31 | 32 | void Timer::start() { 33 | totalWallTime=0; 34 | totalCPUtime=0; 35 | totalTicksCPU=0; 36 | 37 | resume(); 38 | } 39 | 40 | void Timer::pause(void) { 41 | TimeValue_t currentTicksCPU, currentWallSeconds, currentWallNanoseconds; 42 | getCurrentTimeValues(currentTicksCPU, 43 | currentWallSeconds, 44 | currentWallNanoseconds); 45 | 46 | totalTicksCPU = currentTicksCPU-startTicksCPU; 47 | totalCPUtime += (static_cast(totalTicksCPU))/CLOCKS_PER_SEC; 48 | 49 | totalWallTime += (currentWallSeconds - startWallSeconds); 50 | totalWallTime += 51 | (currentWallNanoseconds - startWallNanoseconds) / 1000000000.0; 52 | } 53 | 54 | void Timer::resume(void) { 55 | getCurrentTimeValues(startTicksCPU, startWallSeconds, startWallNanoseconds); 56 | } 57 | 58 | void Timer::stop(void) { 59 | pause(); 60 | } 61 | 62 | void Timer::reportTime(YAML_Doc &doc) const { 63 | CLOG(logYAML) << "Total Program CPU Time (clicks): " << totalTicksCPU; 64 | CLOG(logYAML) << "Total Program CPU Time (seconds): " << totalCPUtime; 65 | CLOG(logYAML) << "Total Program WALL Time (seconds): " << totalWallTime; 66 | doc.add("Total Program CPU Time (clicks)",static_cast(totalTicksCPU)); 67 | doc.add("Total Program CPU Time (seconds)",totalCPUtime); 68 | doc.add("Total Program WALL Time (seconds)",totalWallTime); 69 | } 70 | 71 | Timer::~Timer() { 72 | // TODO Auto-generated destructor stub 73 | } 74 | 75 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/Reporting/Timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Timer.h 3 | * 4 | * Created on: Jul 17, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef REPORTING_TIMER_H_ 9 | #define REPORTING_TIMER_H_ 10 | 11 | #include"../includes.h" 12 | 13 | // Reporting Headers 14 | #include"YAML_Element.hpp" 15 | #include"YAML_Doc.hpp" 16 | #include"Log.h" 17 | 18 | class Timer { 19 | public: 20 | Timer(); 21 | //Timer(bool); 22 | virtual ~Timer(); 23 | 24 | //void startForProcess(void); 25 | 26 | void start(void); 27 | 28 | void pause(void); 29 | void resume(void); 30 | 31 | void stop(void); 32 | void reportTime(YAML_Doc &) const; 33 | void reportTime(void) const; 34 | 35 | // For message passing 36 | const double getWallTime (void) { return totalWallTime; }; 37 | const double getCPUtime (void) { return totalCPUtime; }; 38 | 39 | private: 40 | typedef long long TimeValue_t; 41 | 42 | TimeValue_t startTicksCPU; 43 | TimeValue_t startWallSeconds; 44 | TimeValue_t startWallNanoseconds; 45 | double totalWallTime; 46 | double totalCPUtime; 47 | TimeValue_t totalTicksCPU; 48 | 49 | void getCurrentTimeValues(TimeValue_t &ticksCPU, 50 | TimeValue_t &wallSeconds, 51 | TimeValue_t &wallNanoseconds) const; 52 | }; 53 | 54 | #endif /* REPORTING_TIMER_H_ */ 55 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/Reporting/YAML_Doc.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #ifdef REDSTORM 9 | #include 10 | #include 11 | #include 12 | #endif 13 | #include "YAML_Doc.hpp" 14 | using namespace std; 15 | 16 | //set the microapp_name and version which will become part of the YAML doc. 17 | YAML_Doc::YAML_Doc(const std::string& miniApp_Name, const std::string& miniApp_Version, const std::string& destination_Directory, const std::string& destination_FileName){ 18 | miniAppName = miniApp_Name; 19 | miniAppVersion = miniApp_Version; 20 | destinationDirectory = destination_Directory; 21 | destinationFileName = destination_FileName; 22 | } 23 | 24 | //inherits the destructor from YAML_Element 25 | YAML_Doc::~YAML_Doc(void){ 26 | } 27 | 28 | /* 29 | * generates YAML from the elements of the document and saves it 30 | * to a file 31 | */ 32 | string YAML_Doc::generateYAML(){ 33 | string yaml; 34 | yaml = yaml + "Mini-Application Name: " + miniAppName + "\n"; 35 | yaml = yaml + "Mini-Application Version: " + miniAppVersion + "\n"; 36 | for(size_t i=0; iprintYAML(""); 38 | } 39 | 40 | time_t rawtime; 41 | tm * ptm; 42 | time ( &rawtime ); 43 | ptm = localtime(&rawtime); 44 | char sdate[25]; 45 | //use tm_mon+1 because tm_mon is 0 .. 11 instead of 1 .. 12 46 | sprintf (sdate,"%04d:%02d:%02d-%02d:%02d:%02d",ptm->tm_year + 1900, ptm->tm_mon+1, 47 | ptm->tm_mday, ptm->tm_hour, ptm->tm_min,ptm->tm_sec); 48 | 49 | string filename; 50 | if (destinationFileName=="") 51 | filename = miniAppName + "-" + miniAppVersion + "_"; 52 | else 53 | filename = destinationFileName; 54 | filename = filename + string(sdate) + ".yaml"; 55 | if (destinationDirectory!="" && destinationDirectory!=".") { 56 | string mkdir_cmd = "mkdir " + destinationDirectory; 57 | #ifdef REDSTORM 58 | mkdir(destinationDirectory.c_str(),0755); 59 | #else 60 | system(mkdir_cmd.c_str()); 61 | #endif 62 | filename = destinationDirectory + "/" + destinationFileName; 63 | } 64 | else 65 | filename = "./" + filename; 66 | 67 | ofstream myfile; 68 | myfile.open(filename.c_str()); 69 | myfile << yaml; 70 | myfile.close(); 71 | return yaml; 72 | } 73 | 74 | 75 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/User_Interface/UI.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * UI.cpp 3 | * 4 | * Created on: Jul 27, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #include "UI.h" 9 | 10 | template 11 | UI::UI(int argc, char* argv[]) { 12 | 13 | if (argc==4) { 14 | filePath = argv[1]; 15 | outFilePath = argv[2]; 16 | isoval = atof(argv[3]); 17 | this->checkDebugLevel(); 18 | dataFilePath=0; 19 | headerSeperate=false; 20 | } 21 | else if (argc == 5) { 22 | filePath = argv[1]; 23 | dataFilePath = argv[2]; 24 | outFilePath = argv[3]; 25 | isoval = atof(argv[4]); 26 | this->checkDebugLevel(); 27 | headerSeperate=true; 28 | } 29 | 30 | } 31 | 32 | template 33 | const char * UI::getFile(void) const { 34 | return filePath; 35 | } 36 | 37 | template 38 | const char * UI::getDataFile(void) const { 39 | if (headerSeperate) { 40 | return dataFilePath; 41 | } 42 | else { 43 | return 0; 44 | } 45 | } 46 | 47 | template 48 | const char * UI::outFile(void) const { 49 | return outFilePath; 50 | } 51 | 52 | template 53 | T UI::getIsoVal(void) const { 54 | return isoval; 55 | } 56 | 57 | 58 | template 59 | void UI::checkDebugLevel(void) const { 60 | if (LOG::ReportingLevel() == logDEBUG_Step) { 61 | CLOG(logWARNING) << "Step by step debugging output is active"; 62 | CLOG(logWARNING) 63 | << "Only image volumes with up to 1000 points will be accepted"; 64 | } 65 | } 66 | 67 | template 68 | void UI::checkArgs(int argc) { 69 | if (argc != 4 && argc != 5) { 70 | throw wrong_arguments(argc); 71 | } 72 | } 73 | 74 | // Must instantiate class for separate compilation 75 | template class UI ; 76 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/User_Interface/UI.h: -------------------------------------------------------------------------------- 1 | /* 2 | * UI.h 3 | * 4 | * Created on: Jul 27, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef USER_INTERFACE_UI_H_ 9 | #define USER_INTERFACE_UI_H_ 10 | // Standard C/C++ library 11 | #include"../includes.h" 12 | 13 | // Reporting 14 | #include"../Reporting/RunTime_errors.h" 15 | #include"../Reporting/YAML_Element.hpp" 16 | #include"../Reporting/YAML_Doc.hpp" 17 | #include"../Reporting/Log.h" 18 | 19 | template 20 | class UI { 21 | public: 22 | UI(int argc, char* argv[]); 23 | virtual ~UI() {} ; 24 | 25 | //void marchImplemtation(const Image3D_t &, TriangleMesh_t *&, YAML_Doc&); 26 | const char * getFile(void) const; 27 | const char * getDataFile(void) const; 28 | const char * outFile(void) const; 29 | T getIsoVal(void) const; 30 | 31 | private: 32 | static void checkArgs(int); 33 | void checkDebugLevel(void) const; 34 | 35 | T isoval; 36 | char * filePath; 37 | char * dataFilePath; 38 | char * outFilePath; 39 | bool headerSeperate; 40 | }; 41 | 42 | #endif /* USER_INTERFACE_UI_H_ */ 43 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/includes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * includes.h 3 | * 4 | * Created on: Jul 2, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef INCLUDES_H_ 9 | #define INCLUDES_H_ 10 | 11 | // General in/out 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | // Standard library 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | // Error handling 24 | #include 25 | 26 | // Standard Data Structures 27 | #include // for float_t data type 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | // Parallel computing 34 | //#include 35 | #include 36 | 37 | #endif /* INCLUDES_H_ */ 38 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/common/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * types.h 3 | * 4 | * Created on: Jul 10, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef TYPES_H_ 9 | #define TYPES_H_ 10 | 11 | // Standard library 12 | #include 13 | 14 | // Data Object definitions 15 | #include"./Data_Obj/Image3D.h" 16 | #include"./Data_Obj/TriangleMesh.h" 17 | #include"./Data_Obj/Triplet.h" 18 | #include"./Algorithm/MarchAlgorithm.h" 19 | #include"./Algorithm/EdgeIndexer.h" 20 | 21 | 22 | // Data Object names 23 | typedef Image3D Image3D_t; 24 | typedef TriangleMesh TriangleMesh_t; 25 | typedef EdgeIndexer EdgeIndexer_t; 26 | 27 | typedef Triplet PositionVector_t; 28 | typedef Triplet IndexTriplet_t; 29 | 30 | typedef std::unordered_map PointMap_t; 31 | 32 | #endif /* TYPES_H_ */ 33 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/dataGen/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(dataGen main.cpp) 2 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/dataGen/Makefile: -------------------------------------------------------------------------------- 1 | CC = g++ 2 | CXXFLAGS = -O2 3 | 4 | all: main.o 5 | $(CC) $(CXXFLAGS) main.cpp; -------------------------------------------------------------------------------- /marchingCubes/obsolete/dataGen/main.cpp: -------------------------------------------------------------------------------- 1 | /* Generate synthetic data 2 | for marching cubes */ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | inline void flipEndianness(float &val) { 10 | int mid = sizeof(float) / 2; 11 | char *data = reinterpret_cast(&val); 12 | for (int i = 0; i < mid; ++i) { 13 | std::swap(data[i], data[sizeof(float) - i - 1]); 14 | } 15 | } 16 | 17 | int main(void) { 18 | std::ofstream stream("dataGen.vtk",std::ofstream::binary); 19 | 20 | const unsigned dim = 1024; 21 | const unsigned long nPoints = dim*dim*dim; 22 | 23 | const float mins[3] = { -1, -1, -1 }; 24 | const float maxs[3] = { 1, 1, 1 }; 25 | 26 | float data[dim]; // Save full row of points at a time 27 | int writeSize = dim * sizeof(float); 28 | 29 | /* Write the file header */ 30 | stream << "# vtk DataFile Version 3.0" << std::endl; 31 | stream << "vtk output" << std::endl; 32 | stream << "BINARY" << std::endl; 33 | stream << "DATASET STRUCTURED_POINTS" << std::endl; 34 | stream << "DIMENSIONS " << dim << " " << dim << " " << dim << std::endl; 35 | stream << "SPACING " << "1 1 1" << std::endl; 36 | stream << "ORIGIN 0 0 0" << std::endl; 37 | stream << "POINT_DATA " << nPoints << std::endl; 38 | stream << "SCALARS ImageFile float" << std::endl; 39 | stream << "LOOKUP_TABLE default" << std::endl; 40 | 41 | // Port of Kewei's data generation code from his isosurface implemention 42 | // See isosurface.cpp:TangleField 43 | for (int z = 0; z < dim; ++z){ 44 | for (int y = 0; y < dim; ++y){ 45 | for (int x = 0; x < dim; ++x){ 46 | const float xx = 3.0 * (mins[0] + (maxs[0] - mins[0]) * (1.0 * x / dim)); 47 | const float yy = 3.0 * (mins[1] + (maxs[1] - mins[1]) * (1.0 * y / dim)); 48 | const float zz = 3.0 * (mins[2] + (maxs[2] - mins[2]) * (1.0 * z / dim)); 49 | const float v = (xx*xx*xx*xx - 5.0f*xx*xx + yy*yy*yy*yy - 5.0f*yy*yy 50 | + zz*zz*zz*zz - 5.0f*zz*zz + 11.8f) * 0.2f + 0.5f; 51 | data[x]=v; 52 | flipEndianness(data[x]); 53 | } 54 | 55 | stream.write((char *)data,writeSize); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/mergemp/Algorithm/DuplicateRemover.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * DuplicateRemover.cpp 3 | * 4 | * Created on: Aug 12, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #include "DuplicateRemover.h" 9 | 10 | DuplicateRemover::DuplicateRemover(void) { 11 | // not necessary 12 | edge_sorted=false; 13 | //oldIdx_sorted=false; 14 | } 15 | 16 | void DuplicateRemover::preAllocate(unsigned nPoints) { 17 | dataArray.resize(nPoints); 18 | } 19 | 20 | void DuplicateRemover::setArrays(const PointMap_type &pointMap) { 21 | /* 22 | * This object reverses the point map 23 | * pointMap: edges pointing to point indices 24 | * edgeIdxArray : point indices pointing to edge indices 25 | */ 26 | unsigned nEdges = pointMap.size(); 27 | this->preAllocate(nEdges); 28 | // Start the clock 29 | //Timer RunTime; 30 | //#pragma omp parallel for 31 | for (PointMap_type::const_iterator it = pointMap.begin(); it != pointMap.end(); ++it) { 32 | dataArray[it->second].edgeIdx=it->first; 33 | dataArray[it->second].pointIdx=it->second; 34 | } 35 | // Stop Clock 36 | //RunTime.stop(); 37 | 38 | //Report and save YAML file 39 | //RunTime.reportTime(); 40 | } 41 | 42 | void DuplicateRemover::sortYourSelf(void) { 43 | 44 | std::sort(dataArray.begin(), dataArray.end(), ByEdgeIdx()); 45 | edge_sorted=true; 46 | //oldIdx_sorted=false; 47 | } 48 | 49 | std::vector DuplicateRemover::oldToNewIdxMap(void) { 50 | 51 | unsigned nPoints=getSize(); 52 | std::vector oldToNewMap; 53 | oldToNewMap.resize(nPoints); 54 | 55 | #pragma omp parallel for 56 | for(unsigned iPoint=0;iPointdataArray[0].edgeIdx; 73 | unsigned iEdgeIndxCurrent=this->dataArray[1].edgeIdx; 74 | this->dataArray[0].newPointIdx=0; 75 | unsigned currentPointNum=0; 76 | 77 | unsigned nPoints=this->getSize(); 78 | for (unsigned iPoint=1; iPoint < nPoints; ++iPoint) { 79 | iEdgeIndxCurrent=dataArray[iPoint].edgeIdx; 80 | if (iEdgeIndxCurrent!=iEdgeIndxPrevious) currentPointNum++; 81 | 82 | dataArray[iPoint].newPointIdx=currentPointNum; 83 | iEdgeIndxPrevious=iEdgeIndxCurrent; 84 | } 85 | } 86 | 87 | DuplicateRemover& DuplicateRemover::operator+=(const unsigned increment) { 88 | 89 | # pragma omp parallel for 90 | for (unsigned iPoint=0; iPointgetSize(); iPoint++) { 91 | this->dataArray[iPoint].pointIdx+=increment; 92 | } 93 | 94 | return *this; 95 | } 96 | 97 | DuplicateRemover& DuplicateRemover::operator+=(const DuplicateRemover& threadMap) { 98 | 99 | dataArray.insert(dataArray.end(), threadMap.dataArray.begin(), threadMap.dataArray.end()); 100 | 101 | return *this; 102 | } 103 | 104 | const unsigned DuplicateRemover::getSize(void) const { 105 | 106 | return dataArray.size(); 107 | } 108 | 109 | DuplicateRemover::~DuplicateRemover() { 110 | // TODO Auto-generated destructor stub 111 | } 112 | 113 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/mergemp/Algorithm/DuplicateRemover.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DuplicateRemover.h 3 | * 4 | * Created on: Aug 12, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef IMPLEMENTATIONS_MAPREVERSE_H_ 9 | #define IMPLEMENTATIONS_MAPREVERSE_H_ 10 | 11 | #include"../../common/includes.h" 12 | 13 | // Reporting Headers 14 | #include"../../common/Reporting/Log.h" 15 | #include"../../common/Reporting/IO_errors.h" 16 | #include"../../common/Reporting/Timer.h" 17 | 18 | typedef std::unordered_map PointMap_type; 19 | 20 | struct edgePointPair { 21 | unsigned edgeIdx; 22 | unsigned pointIdx; 23 | unsigned newPointIdx; 24 | }; 25 | 26 | struct ByEdgeIdx { 27 | bool operator()(const edgePointPair &left, const edgePointPair &right) { 28 | return left.edgeIdx < right.edgeIdx; 29 | } 30 | }; 31 | 32 | struct ByPointIdx { 33 | bool operator()(const edgePointPair &left, const edgePointPair &right) { 34 | return left.pointIdx < right.pointIdx; 35 | } 36 | }; 37 | 38 | class DuplicateRemover { 39 | public: 40 | DuplicateRemover(); 41 | virtual ~DuplicateRemover(); 42 | 43 | // write 44 | void preAllocate(const unsigned); 45 | void setArrays(const PointMap_type &); 46 | void sortYourSelf(void); 47 | std::vector oldToNewIdxMap(void); 48 | DuplicateRemover& operator+=(const unsigned); 49 | DuplicateRemover& operator+=(const DuplicateRemover&); 50 | void getNewIndices(void); 51 | 52 | //read 53 | const unsigned getSize(void) const; 54 | 55 | std::vector dataArray; 56 | bool edge_sorted; 57 | //bool oldIdx_sorted; 58 | }; 59 | 60 | #endif /* IMPLEMENTATIONS_MAPREVERSE_H_ */ 61 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/mergemp/Algorithm/buildMesh.h: -------------------------------------------------------------------------------- 1 | /* 2 | * buildMesh.h 3 | * 4 | * Created on: Aug 19, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef ALGORITHM_BUILDMESH_H_ 9 | #define ALGORITHM_BUILDMESH_H_ 10 | 11 | // External includes 12 | #include"../../common/includes.h" 13 | 14 | // Reporting Headers 15 | #include"../../common/Reporting/YAML_Element.hpp" 16 | #include"../../common/Reporting/YAML_Doc.hpp" 17 | #include"../../common/Reporting/Log.h" 18 | 19 | // Strategy base class 20 | #include"../../common/Data_Obj/TriangleMesh.h" 21 | 22 | #include"./DuplicateRemover.h" 23 | 24 | template 25 | void buildMesh(TriangleMesh& newMesh, TriangleMesh& ogMesh,DuplicateRemover& newPtMap) { 26 | /* 27 | * Iterates through the entire dataArray in newPtMap and creates 28 | * a new mesh from the new point indices in newPointIdx 29 | */ 30 | unsigned nOgPoints=newPtMap.getSize(); 31 | CLOG(logDEBUG) << "nogpoints: " << nOgPoints; 32 | // As many new points as last index in the dataArray 33 | unsigned nNewPoints=newPtMap.dataArray.back().newPointIdx+1; // Because counting from 0 34 | CLOG(logDEBUG) << "newPoints: " << nNewPoints; 35 | // Allocate space in the new mesh 36 | newMesh.allocate(nNewPoints); 37 | 38 | /* 39 | * Assign all the new points and normals correctly 40 | */ 41 | for (unsigned iPoint=0; iPoint < nOgPoints; iPoint++) { 42 | 43 | unsigned newPtIndex=newPtMap.dataArray[iPoint].newPointIdx; 44 | unsigned ogPtIndex=newPtMap.dataArray[iPoint].pointIdx; 45 | const float_t * ogCoords = ogMesh.getPointPosition(ogPtIndex); 46 | const float_t * ogNormal = ogMesh.getNormalVector(ogPtIndex); 47 | 48 | newMesh.setPoint(newPtIndex,ogCoords); 49 | newMesh.setNormal(newPtIndex,ogNormal); 50 | } 51 | 52 | /* 53 | * Get the triangles 54 | */ 55 | unsigned nTriangles = ogMesh.numberOfTriangles(); 56 | std::vector oldToNewMap = newPtMap.oldToNewIdxMap(); 57 | 58 | //# pragma omp parallel for 59 | for (unsigned iTriangle=0; iTriangle < nTriangles;++iTriangle) { 60 | const unsigned *ogTriangleIdxs=ogMesh.getTriangleIndices(iTriangle); 61 | unsigned newTriangleIdxs[3]; 62 | newTriangleIdxs[0]=oldToNewMap[ogTriangleIdxs[0]]; 63 | newTriangleIdxs[1]=oldToNewMap[ogTriangleIdxs[1]]; 64 | newTriangleIdxs[2]=oldToNewMap[ogTriangleIdxs[2]]; 65 | 66 | newMesh.addTriangle(newTriangleIdxs); 67 | } 68 | 69 | } 70 | 71 | 72 | 73 | #endif /* ALGORITHM_BUILDMESH_H_ */ 74 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/mergemp/Algorithm/pointCount.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pointCount.h 3 | * 4 | * Created on: Aug 7, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef ALGORITHM_POINTCOUNT_H_ 9 | #define ALGORITHM_POINTCOUNT_H_ 10 | 11 | // Common utility headers ------------- 12 | // Standard C/C++ library 13 | #include"../../common/includes.h" 14 | 15 | // Data Objects 16 | #include"../../common/types.h" 17 | 18 | typedef Triplet Point3dIdx; 19 | 20 | unsigned countPointsInVolume(const Image3D_t &, const unsigned ext[6], float_t, 21 | EdgeIndexer_t &); 22 | 23 | unsigned countPointsInBlock(const Image3D_t &, const unsigned ext[6], float_t, 24 | EdgeIndexer_t &); 25 | 26 | #endif /* ALGORITHM_POINTCOUNT_H_ */ 27 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/mergemp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(target MCMerge) 2 | 3 | set(srcs 4 | Algorithm/DuplicateRemover.cpp 5 | Implementations/MergeMPAlgo.cpp 6 | ) 7 | 8 | find_package(OpenMP) 9 | 10 | if (NOT OPENMP_FOUND) 11 | message(SEND_ERROR 12 | "Could not find a compatible OpenMP compiler. Consider turning BUILD_OPENMP to OFF") 13 | endif() 14 | 15 | add_executable(${target} main.cpp ${srcs}) 16 | 17 | target_link_libraries(${target} mantevo_marching_cubes_common) 18 | target_compile_options(${target} PUBLIC ${OpenMP_CXX_FLAGS}) 19 | set_target_properties(${target} PROPERTIES LINK_FLAGS ${OpenMP_CXX_FLAGS}) 20 | 21 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/mergemp/Implementations/MergeMPAlgo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SerialAlgo.h 3 | * 4 | * Created on: Aug 17, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef IMPLEMENTATIONS_MERGEMPALGO_H_ 9 | #define IMPLEMENTATIONS_MERGEMPALGO_H_ 10 | 11 | // External includes 12 | #include"../../common/includes.h" 13 | 14 | // Reporting Headers 15 | #include"../../common/Reporting/YAML_Element.hpp" 16 | #include"../../common/Reporting/YAML_Doc.hpp" 17 | #include"../../common/Reporting/Log.h" 18 | 19 | // Strategy base class 20 | #include"../../common/Algorithm/MarchAlgorithm.h" 21 | #include"../../common/GeneralContext/GeneralContext.h" 22 | 23 | #include"../../common/Data_Obj/TriangleMesh.h" 24 | 25 | // Algorithm objects 26 | #include"../../common/Algorithm/Ranges.h" 27 | 28 | #include"../Algorithm/DuplicateRemover.h" 29 | #include"../Algorithm/buildMesh.h" 30 | 31 | 32 | template 33 | class MergeMPAlgo : public MarchAlgorithm { 34 | public: 35 | MergeMPAlgo(); 36 | MergeMPAlgo(unsigned); 37 | virtual ~MergeMPAlgo(); 38 | 39 | unsigned numBlocks(const Range oneDRange); 40 | void march(GeneralContext &); 41 | private: 42 | // These are intermediate data structures before the final 43 | // results are sent to GeneralContext 44 | DuplicateRemover duplicateRemover; 45 | TriangleMesh meshBeforeMerge; 46 | unsigned grainDim; 47 | }; 48 | 49 | #endif /* IMPLEMENTATIONS_MERGEMPALGO_H_ */ 50 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/mergemp/Makefile: -------------------------------------------------------------------------------- 1 | # ----------------------------------------------- 2 | # Mantevo Marching Cubes OpenMP Implementation 3 | # with Merger algorithm 4 | # 5 | # Author: sjmunn@sandia.gov 6 | # Date : 2015-07-31 7 | # 8 | # Changelog : 9 | # 2015-07-31 - created 10 | # ----------------------------------------------- 11 | 12 | # ========== Macros ============================= 13 | 14 | # project name (generate executable with this name) 15 | TARGET = MCMerge.exe 16 | 17 | # Compiler and flags 18 | CC = g++ 19 | CXXFLAGS = -O2 -fopenmp -std=c++0x 20 | #GPERF_FLAG = -lprofiler 21 | #CXXFLAGS = -O0 -g -fopenmp -std=c++0x 22 | 23 | # Source and build directories 24 | SRCDIRS = Algorithm Implementations User_Interface 25 | BUILD_DIRECTORY = build 26 | BUILDDIR = $(BUILD_DIRECTORY) 27 | 28 | # Utility object code 29 | UTILS_DIR = ../common/build 30 | 31 | # Get source code files and generate object names 32 | SOURCES := $(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.cpp)) 33 | OBJECTS := $(addprefix $(BUILDDIR)/,$(notdir $(SOURCES:.cpp=.o))) 34 | UTILS_OBJ := $(wildcard $(UTILS_DIR)/*.o) 35 | 36 | # ========== Compiler Rules ===================== 37 | 38 | # Linker commands 39 | 40 | all: main.o $(OBJECTS) $(UTILS_OBJ) 41 | @echo "Linking object files..."; 42 | @$(CC) $(CXXFLAGS) $(BUILDDIR)/main.o $(OBJECTS) $(UTILS_OBJ) -o $(BUILDDIR)/$(TARGET) $(GPERF_FLAG); 43 | @echo "Compiled and linked "$(BUILDDIR)/$(TARGET)" successfully!" 44 | 45 | # Compiler commands 46 | 47 | main.o: main.cpp 48 | @mkdir -p $(BUILDDIR); 49 | @echo "Compiling "$(BUILDDIR)/$@; 50 | @$(CC) $(CXXFLAGS) -c main.cpp -o $(BUILDDIR)/$@; 51 | 52 | # General purpose object code compiler 53 | $(BUILDDIR)/%.o: ./*/%.cpp 54 | @mkdir -p $(BUILDDIR); 55 | @echo "Compiling "$@; 56 | @$(CC) $(CXXFLAGS) -c $< -o $@; 57 | 58 | # ========== Cleanup Rules ====================== 59 | 60 | .PHONEY: clean 61 | clean: 62 | rm -f $(BUILDDIR)/*.o; 63 | 64 | .PHONEY: clean_run_data 65 | clean_run_data: 66 | rm -f yaml_out.*; 67 | rm -f callgrind.*; 68 | 69 | .PHONEY: deepclean 70 | deepclean: clean clean_run_data 71 | rm -rf $(BUILDDIR); 72 | 73 | # ========== Debug Rules ======================== 74 | 75 | debug: 76 | @echo "Using compiler: " 77 | @echo $(CC) 78 | @echo "With flags: " 79 | @echo $(CXXFLAGS) 80 | @echo "Source code directories: " 81 | @echo $(SRCDIRS); 82 | @echo "Source code files: " 83 | @echo $(SOURCES); 84 | @echo "Object files: " 85 | @echo $(OBJECTS); -------------------------------------------------------------------------------- /marchingCubes/obsolete/mergemp/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * main.cpp 3 | * 4 | * Created on: Jul 2, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | // Common utility headers ------------- 9 | // Standard C/C++ library 10 | #include"../common/includes.h" 11 | 12 | // File i/o 13 | #include"../common/IO/LoadImage3DMPI.h" 14 | #include"../common/IO/SaveTriangleMesh.h" 15 | 16 | // Reporting 17 | #include"../common/Reporting/YAML_Element.hpp" 18 | #include"../common/Reporting/YAML_Doc.hpp" 19 | #include"../common/Reporting/Log.h" 20 | #include"../common/Reporting/Timer.h" 21 | 22 | #include"../common/User_Interface/UI.h" 23 | 24 | // Data Objects 25 | #include"../common/types.h" 26 | 27 | // Local implementation headers ------- 28 | // Algorithm 29 | #include"./Implementations/MergeMPAlgo.h" 30 | 31 | int main(int argc, char* argv[]) { 32 | 33 | LOG::ReportingLevel() = logDEBUG1; // Debug level is hard coded 34 | 35 | // Initialize the user interface 36 | UI mainUI(argc,argv); 37 | 38 | // Create data object 39 | GeneralContext data; 40 | 41 | LoadImage3DMPI fileHeader; 42 | fileHeader.loadHeader(mainUI.getFile()); 43 | fileHeader.setSperateData(mainUI.getDataFile()); 44 | 45 | LoadImage3DMPI fileData(fileHeader); // We will need multiple data loaders in MPI 46 | fileData.readEntireVolumeData(data.imageIn); 47 | 48 | // Report file data characteristics 49 | CLOG(logYAML) << "Volume image data file path: " << mainUI.getFile(); 50 | data.doc.add("Volume image data file path", mainUI.getFile()); 51 | fileHeader.report(data.doc); 52 | 53 | // Start the clock 54 | Timer RunTime; 55 | // Execute the marching cubes implementation 56 | data.isoval=mainUI.getIsoVal(); 57 | MergeMPAlgo algorithm; 58 | data.setAlgorithm(&algorithm); 59 | data.march(); 60 | // Stop Clock 61 | RunTime.stop(); 62 | 63 | //Report and save YAML file 64 | RunTime.reportTime(data.doc); 65 | data.doc.generateYAML(); 66 | 67 | // Save the result 68 | saveTriangleMesh(&(data.mesh), mainUI.outFile()); 69 | return 0; 70 | } 71 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/mpi/Algorithm/DuplicateRemover.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * DuplicateRemover.cpp 3 | * 4 | * Created on: Aug 12, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #include "DuplicateRemover.h" 9 | 10 | DuplicateRemover::DuplicateRemover(void) { 11 | // not necessary 12 | edge_sorted=false; 13 | //oldIdx_sorted=false; 14 | } 15 | 16 | void DuplicateRemover::preAllocate(unsigned nPoints) { 17 | dataArray.resize(nPoints); 18 | } 19 | 20 | void DuplicateRemover::setArrays(const PointMap_type &pointMap) { 21 | /* 22 | * This object reverses the point map 23 | * pointMap: edges pointing to point indices 24 | * edgeIdxArray : point indices pointing to edge indices 25 | */ 26 | unsigned nEdges = pointMap.size(); 27 | this->preAllocate(nEdges); 28 | // Start the clock 29 | //Timer RunTime; 30 | //#pragma omp parallel for 31 | for (PointMap_type::const_iterator it = pointMap.begin(); it != pointMap.end(); ++it) { 32 | dataArray[it->second].edgeIdx=it->first; 33 | dataArray[it->second].pointIdx=it->second; 34 | } 35 | // Stop Clock 36 | //RunTime.stop(); 37 | 38 | //Report and save YAML file 39 | //RunTime.reportTime(); 40 | } 41 | 42 | void DuplicateRemover::sortYourSelf(void) { 43 | 44 | std::sort(dataArray.begin(), dataArray.end(), ByEdgeIdx()); 45 | edge_sorted=true; 46 | //oldIdx_sorted=false; 47 | } 48 | 49 | std::vector DuplicateRemover::oldToNewIdxMap(void) { 50 | 51 | unsigned nPoints=this->getSize(); 52 | std::vector oldToNewMap; 53 | //CLOG(logDEBUG) << "!!!!!!!!!!!!!!! nPoints oldToNewIdxMap " << nPoints << " !!!!!!!!!!!!!"; 54 | oldToNewMap.resize(nPoints); 55 | 56 | //#pragma omp parallel for 57 | for(unsigned iPoint=0;iPoint3) { // Block contains at least one triangle 70 | /* 71 | * Going through the dataArray and creating new point indices for the data 72 | */ 73 | // Initialize run 74 | unsigned iEdgeIndxPrevious=dataArray[0].edgeIdx; 75 | unsigned iEdgeIndxCurrent=dataArray[1].edgeIdx; 76 | dataArray[0].newPointIdx=0; 77 | unsigned currentPointNum=0; 78 | 79 | unsigned nPoints=this->getSize(); 80 | for (unsigned iPoint=1; iPoint < nPoints; iPoint++) { 81 | iEdgeIndxCurrent=dataArray[iPoint].edgeIdx; 82 | if (iEdgeIndxCurrent!=iEdgeIndxPrevious) currentPointNum++; 83 | 84 | dataArray[iPoint].newPointIdx=currentPointNum; 85 | iEdgeIndxPrevious=iEdgeIndxCurrent; 86 | } 87 | } 88 | } 89 | 90 | DuplicateRemover& DuplicateRemover::operator+=(const unsigned increment) { 91 | 92 | //# pragma omp parallel for 93 | for (unsigned iPoint=0; iPointgetSize(); iPoint++) { 94 | this->dataArray[iPoint].pointIdx+=increment; 95 | } 96 | 97 | return *this; 98 | } 99 | 100 | DuplicateRemover& DuplicateRemover::operator+=(const DuplicateRemover&threadMap) { 101 | 102 | dataArray.insert(dataArray.end(), threadMap.dataArray.begin(), threadMap.dataArray.end()); 103 | 104 | return *this; 105 | } 106 | 107 | const unsigned DuplicateRemover::getSize(void) const { 108 | 109 | return dataArray.size(); 110 | } 111 | 112 | //DuplicateRemover::~DuplicateRemover() { 113 | // // TODO Auto-generated destructor stub 114 | //} 115 | 116 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/mpi/Algorithm/DuplicateRemover.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DuplicateRemover.h 3 | * 4 | * Created on: Aug 12, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef IMPLEMENTATIONS_MAPREVERSE_H_ 9 | #define IMPLEMENTATIONS_MAPREVERSE_H_ 10 | 11 | #include"../../common/includes.h" 12 | 13 | // Reporting Headers 14 | #include"../../common/Reporting/Log.h" 15 | #include"../../common/Reporting/IO_errors.h" 16 | #include"../../common/Reporting/Timer.h" 17 | 18 | typedef std::unordered_map PointMap_type; 19 | 20 | struct edgePointPair { 21 | unsigned edgeIdx; 22 | unsigned pointIdx; 23 | unsigned newPointIdx; 24 | }; 25 | 26 | struct ByEdgeIdx { 27 | bool operator()(const edgePointPair &left, const edgePointPair &right) { 28 | return left.edgeIdx < right.edgeIdx; 29 | } 30 | }; 31 | 32 | struct ByPointIdx { 33 | bool operator()(const edgePointPair &left, const edgePointPair &right) { 34 | return left.pointIdx < right.pointIdx; 35 | } 36 | }; 37 | 38 | class DuplicateRemover { 39 | public: 40 | DuplicateRemover(); 41 | // virtual ~DuplicateRemover(); 42 | 43 | // write 44 | void preAllocate(const unsigned); 45 | void setArrays(const PointMap_type &); 46 | void sortYourSelf(void); 47 | std::vector oldToNewIdxMap(void); 48 | DuplicateRemover& operator+=(const unsigned); 49 | DuplicateRemover& operator+=(const DuplicateRemover&); 50 | void getNewIndices(void); 51 | 52 | //read 53 | const unsigned getSize(void) const; 54 | 55 | std::vector dataArray; 56 | bool edge_sorted; 57 | //bool oldIdx_sorted; 58 | }; 59 | 60 | #endif /* IMPLEMENTATIONS_MAPREVERSE_H_ */ 61 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/mpi/Algorithm/buildMesh.h: -------------------------------------------------------------------------------- 1 | /* 2 | * buildMesh.h 3 | * 4 | * Created on: Aug 19, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef ALGORITHM_BUILDMESH_H_ 9 | #define ALGORITHM_BUILDMESH_H_ 10 | 11 | // External includes 12 | #include"../../common/includes.h" 13 | 14 | // Reporting Headers 15 | #include"../../common/Reporting/YAML_Element.hpp" 16 | #include"../../common/Reporting/YAML_Doc.hpp" 17 | #include"../../common/Reporting/Log.h" 18 | 19 | // Strategy base class 20 | #include"../../common/Data_Obj/TriangleMesh.h" 21 | 22 | #include"./DuplicateRemover.h" 23 | 24 | #include"mpi.h" 25 | 26 | template 27 | void buildMesh(TriangleMesh& newMesh, const TriangleMesh& ogMesh,DuplicateRemover& newPtMap) { 28 | /* 29 | * Iterates through the entire dataArray in newPtMap and creates 30 | * a new mesh from the new point indices in newPointIdx 31 | */ 32 | unsigned nOgPoints=newPtMap.getSize(); 33 | // As many new points as last index in the dataArray 34 | unsigned nNewPoints=newPtMap.dataArray.back().newPointIdx+1; // Because counting from 0 35 | // Allocate space in the new mesh 36 | newMesh.allocate(nNewPoints); 37 | 38 | /* 39 | * Assign all the new points and normals correctly 40 | */ 41 | for (unsigned iPoint=0; iPoint < nOgPoints; iPoint++) { 42 | 43 | unsigned newPtIndex=newPtMap.dataArray[iPoint].newPointIdx; 44 | unsigned ogPtIndex=newPtMap.dataArray[iPoint].pointIdx; 45 | const float_t * ogCoords = ogMesh.getPointPosition(ogPtIndex); 46 | const float_t * ogNormal = ogMesh.getNormalVector(ogPtIndex); 47 | 48 | newMesh.setPoint(newPtIndex,ogCoords); 49 | newMesh.setNormal(newPtIndex,ogNormal); 50 | } 51 | 52 | /* 53 | * Get the triangles 54 | */ 55 | unsigned nTriangles = ogMesh.numberOfTriangles(); 56 | std::vector oldToNewMap = newPtMap.oldToNewIdxMap(); 57 | 58 | //# pragma omp parallel for 59 | for (unsigned iTriangle=0; iTriangle < nTriangles;++iTriangle) { 60 | const unsigned *ogTriangleIdxs=ogMesh.getTriangleIndices(iTriangle); 61 | unsigned newTriangleIdxs[3]; 62 | newTriangleIdxs[0]=oldToNewMap[ogTriangleIdxs[0]]; 63 | newTriangleIdxs[1]=oldToNewMap[ogTriangleIdxs[1]]; 64 | newTriangleIdxs[2]=oldToNewMap[ogTriangleIdxs[2]]; 65 | 66 | newMesh.addTriangle(newTriangleIdxs); 67 | } 68 | 69 | } 70 | 71 | 72 | 73 | #endif /* ALGORITHM_BUILDMESH_H_ */ 74 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/mpi/Algorithm/pointCount.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pointCount.h 3 | * 4 | * Created on: Aug 7, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef ALGORITHM_POINTCOUNT_H_ 9 | #define ALGORITHM_POINTCOUNT_H_ 10 | 11 | // Common utility headers ------------- 12 | // Standard C/C++ library 13 | #include"../../common/includes.h" 14 | 15 | // Data Objects 16 | #include"../../common/types.h" 17 | 18 | typedef Triplet Point3dIdx; 19 | 20 | unsigned countPointsInVolume(const Image3D_t &, const unsigned ext[6], float_t, 21 | EdgeIndexer_t &); 22 | 23 | unsigned countPointsInBlock(const Image3D_t &, const unsigned ext[6], float_t, 24 | EdgeIndexer_t &); 25 | 26 | #endif /* ALGORITHM_POINTCOUNT_H_ */ 27 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/mpi/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(target MCMpi) 2 | 3 | set(srcs 4 | Algorithm/DuplicateRemover.cpp 5 | Implementations/MpiAlgo.cpp 6 | ) 7 | 8 | find_package(MPI) 9 | 10 | if(NOT MPI_CXX_FOUND) 11 | message(SEND_ERROR 12 | "Could not find a compatible MPI compiler. Consider turning BUILD_MPI to OFF") 13 | endif() 14 | 15 | add_executable(${target} main.cpp ${srcs}) 16 | 17 | target_include_directories(${target} 18 | PUBLIC "${MPI_CXX_INCLUDE_PATH}" 19 | ) 20 | target_link_libraries(${target} 21 | mantevo_marching_cubes_common 22 | ${MPI_CXX_LIBRARIES} 23 | ) 24 | target_compile_options(${target} 25 | PUBLIC ${MPI_CXX_COMPILE_FLAGS} 26 | ) 27 | set_target_properties(${target} 28 | PROPERTIES LINK_FLAGS "${MPI_CXX_LINK_FLAGS}" 29 | ) 30 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/mpi/Implementations/MpiAlgo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SerialAlgo.h 3 | * 4 | * Created on: Aug 17, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef IMPLEMENTATIONS_MERGEMPALGO_H_ 9 | #define IMPLEMENTATIONS_MERGEMPALGO_H_ 10 | 11 | // External includes 12 | #include"../../common/includes.h" 13 | 14 | // Reporting Headers 15 | #include"../../common/Reporting/YAML_Element.hpp" 16 | #include"../../common/Reporting/YAML_Doc.hpp" 17 | #include"../../common/Reporting/Log.h" 18 | #include"../../common/Reporting/Timer.h" 19 | 20 | // Strategy base class 21 | #include"../../common/Algorithm/MarchAlgorithm.h" 22 | #include"../../common/GeneralContext/GeneralContext.h" 23 | 24 | #include"../../common/Data_Obj/TriangleMesh.h" 25 | 26 | // Algorithm objects 27 | #include"../../common/Algorithm/Ranges.h" 28 | 29 | #include"../Algorithm/DuplicateRemover.h" 30 | #include"../Algorithm/buildMesh.h" 31 | 32 | // IO Object 33 | #include"../../common/IO/LoadImage3DMPI.h" 34 | 35 | #include"../../common/IO/SaveTriangleMesh.h" 36 | 37 | //MPI 38 | #include"mpi.h" 39 | 40 | template 41 | class MpiAlgo : public MarchAlgorithm { 42 | public: 43 | MpiAlgo(LoadImage3DMPI &, int, int, Timer *); 44 | virtual ~MpiAlgo(); 45 | static bool testZeroExtent(unsigned *); 46 | 47 | unsigned numBlocks(const Range oneDRange); 48 | void march(GeneralContext &); 49 | private: 50 | // These are intermediate data structures before the final 51 | // results are sent to GeneralContext 52 | DuplicateRemover duplicateRemover; 53 | TriangleMesh * meshBeforeMerge; 54 | unsigned grainDim; 55 | 56 | // MPI specific 57 | LoadImage3DMPI fileHeader; 58 | int pID,processes; 59 | Timer *processTimer; 60 | }; 61 | 62 | #endif /* IMPLEMENTATIONS_MERGEMPALGO_H_ */ 63 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/mpi/MPIclockFunctions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MPIclockFunctions.h 3 | * 4 | * Created on: Aug 27, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef MPICLOCKFUNCTIONS_H_ 9 | #define MPICLOCKFUNCTIONS_H_ 10 | 11 | // Reporting 12 | #include"../common/Reporting/YAML_Element.hpp" 13 | #include"../common/Reporting/YAML_Doc.hpp" 14 | #include"../common/Reporting/Log.h" 15 | #include"../common/Reporting/Timer.h" 16 | 17 | #include"mpi.h" 18 | 19 | void collectTimesMPI(YAML_Doc &doc, Timer * runTime) { 20 | // Get the individual process ID. 21 | int pID = MPI::COMM_WORLD.Get_rank(); 22 | int nProcesses = MPI::COMM_WORLD.Get_size(); 23 | 24 | double wallTime = runTime->getWallTime(); 25 | double *wallTimes = NULL; 26 | if (pID == 0) { 27 | wallTimes = new double [nProcesses]; 28 | } 29 | MPI_Gather(&wallTime, 1, MPI_DOUBLE, wallTimes, 1, MPI_DOUBLE, 0, 30 | MPI_COMM_WORLD); 31 | double CPUtime = runTime->getWallTime(); 32 | double *CPUtimes = NULL; 33 | if (pID == 0) { 34 | CPUtimes = new double [nProcesses]; 35 | } 36 | MPI_Gather(&CPUtime, 1, MPI_DOUBLE, CPUtimes, 1, MPI_DOUBLE, 0, 37 | MPI_COMM_WORLD); 38 | 39 | // Generate a final report of the execution times 40 | if (pID == 0) { 41 | double maxWallTime=0; 42 | double totalCPU=0; 43 | for (int iPID=0;iPID(iPID)) + " CPU Time (seconds)"; 48 | std::string reportWall = "Process number, " 49 | + std::to_string(static_cast(iPID)) + " Wall Time (seconds):"; 50 | doc.add(reportCPU,wallTimes[iPID]); 51 | doc.add(reportWall,wallTimes[iPID]); 52 | if (wallTimes[iPID] > maxWallTime) maxWallTime=wallTimes[iPID]; 53 | totalCPU+=CPUtimes[iPID]; 54 | } 55 | CLOG(logYAML) << "Total CPU time: " << totalCPU; 56 | CLOG(logYAML) << "Overall wall time: " << maxWallTime; 57 | doc.add("Total CPU time: ",totalCPU); 58 | doc.add("Overall wall time: ",maxWallTime); 59 | } 60 | doc.generateYAML(); 61 | } 62 | 63 | #endif /* MPICLOCKFUNCTIONS_H_ */ 64 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/mpi/Makefile: -------------------------------------------------------------------------------- 1 | # ----------------------------------------------- 2 | # Mantevo Marching Cubes OpenMP Implementation 3 | # with Merger algorithm 4 | # 5 | # Author: sjmunn@sandia.gov 6 | # Date : 2015-07-31 7 | # 8 | # Changelog : 9 | # 2015-07-31 - created 10 | # ----------------------------------------------- 11 | 12 | # ========== Macros ============================= 13 | 14 | # project name (generate executable with this name) 15 | TARGET = MCMpi.exe 16 | 17 | # Compiler and flags 18 | CC = mpic++ 19 | CXXFLAGS = -O2 -lrt -std=c++0x 20 | #CXXFLAGS = -O0 -g -fopenmp -std=c++0x 21 | 22 | # Source and build directories 23 | SRCDIRS = Algorithm Implementations User_Interface 24 | BUILD_DIRECTORY = build 25 | BUILDDIR = $(BUILD_DIRECTORY) 26 | 27 | # Utility object code 28 | UTILS_DIR = ../common/build 29 | 30 | # Get source code files and generate object names 31 | SOURCES := $(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.cpp)) 32 | OBJECTS := $(addprefix $(BUILDDIR)/,$(notdir $(SOURCES:.cpp=.o))) 33 | UTILS_OBJ := $(wildcard $(UTILS_DIR)/*.o) 34 | 35 | # ========== Compiler Rules ===================== 36 | 37 | # Linker commands 38 | 39 | all: main.o $(OBJECTS) $(UTILS_OBJ) 40 | @echo "Linking object files..."; 41 | @$(CC) $(CXXFLAGS) $(BUILDDIR)/main.o $(UTILS_OBJ) $(OBJECTS) -o $(BUILDDIR)/$(TARGET) $(GPERF_FLAG); 42 | @echo "Compiled and linked "$(BUILDDIR)/$(TARGET)" successfully!" 43 | 44 | # Compiler commands 45 | 46 | main.o: main.cpp 47 | @mkdir -p $(BUILDDIR); 48 | @echo "Compiling "$(BUILDDIR)/$@; 49 | @$(CC) $(CXXFLAGS) -c main.cpp -o $(BUILDDIR)/$@; 50 | 51 | # General purpose object code compiler 52 | $(BUILDDIR)/%.o: ./*/%.cpp 53 | @mkdir -p $(BUILDDIR); 54 | @echo "Compiling "$@; 55 | @$(CC) $(CXXFLAGS) -c $< -o $@; 56 | 57 | # ========== Cleanup Rules ====================== 58 | 59 | .PHONEY: clean 60 | clean: 61 | rm -f $(BUILDDIR)/*.o; 62 | 63 | .PHONEY: clean_run_data 64 | clean_run_data: 65 | rm -f yaml_out.*; 66 | rm -f callgrind.*; 67 | 68 | .PHONEY: deepclean 69 | deepclean: clean clean_run_data 70 | rm -rf $(BUILDDIR); 71 | 72 | # ========== Debug Rules ======================== 73 | 74 | debug: 75 | @echo "Using compiler: " 76 | @echo $(CC) 77 | @echo "With flags: " 78 | @echo $(CXXFLAGS) 79 | @echo "Source code directories: " 80 | @echo $(SRCDIRS); 81 | @echo "Source code files: " 82 | @echo $(SOURCES); 83 | @echo "Object files: " 84 | @echo $(OBJECTS); 85 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/mpi/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * main.cpp 3 | * 4 | * Created on: Jul 2, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | // Common utility headers ------------- 9 | // Standard C/C++ library 10 | #include"../common/includes.h" 11 | 12 | // File i/o 13 | #include"../common/IO/LoadImage3DMPI.h" 14 | #include"../common/IO/SaveTriangleMesh.h" 15 | 16 | // Reporting 17 | #include"../common/Reporting/YAML_Element.hpp" 18 | #include"../common/Reporting/YAML_Doc.hpp" 19 | #include"../common/Reporting/Log.h" 20 | #include"../common/Reporting/Timer.h" 21 | 22 | #include"../common/User_Interface/UI.h" 23 | 24 | // Data Objects 25 | #include"../common/types.h" 26 | 27 | // Local implementation headers ------- 28 | // Algorithm 29 | #include"./Implementations/MpiAlgo.h" 30 | 31 | // Deals with each thread's timer: 32 | #include"./MPIclockFunctions.h" 33 | 34 | int main(int argc, char* argv[]) { 35 | 36 | LOG::ReportingLevel() = logDEBUG1; // Debug level is hard coded 37 | 38 | int id; 39 | int nProcesses; 40 | 41 | // Initialize MPI 42 | MPI::Init(argc, argv); 43 | // Get the number of processes. 44 | nProcesses = MPI::COMM_WORLD.Get_size(); 45 | // Get the individual process ID. 46 | id = MPI::COMM_WORLD.Get_rank(); 47 | 48 | // Initialize the user interface 49 | UI mainUI(argc, argv); 50 | 51 | // Create data object 52 | GeneralContext data; 53 | 54 | // Only load the header file, MpiAlgo will read the rest 55 | LoadImage3DMPI fileHeader; 56 | fileHeader.loadHeader(mainUI.getFile()); 57 | 58 | // Report file data characteristics 59 | CLOG(logYAML) << "Volume image data file path: " << mainUI.getFile(); 60 | data.doc.add("Volume image data file path", mainUI.getFile()); 61 | fileHeader.report(data.doc); 62 | 63 | // Start the clock 64 | Timer runTime; 65 | // Execute the marching cubes implementation 66 | data.isoval = mainUI.getIsoVal(); 67 | MpiAlgo algorithm(fileHeader, id, nProcesses, &runTime); 68 | data.setAlgorithm(&algorithm); 69 | data.march(); 70 | // Stop Clock 71 | runTime.stop(); 72 | 73 | collectTimesMPI(data.doc,&runTime); 74 | 75 | // Save the result 76 | const char * baseName = mainUI.outFile(); 77 | std::string outFile = baseName; 78 | outFile = outFile + "." + std::to_string(static_cast(id)); 79 | saveTriangleMesh(&(data.mesh), outFile.c_str()); 80 | 81 | // 82 | // Terminate MPI. 83 | // 84 | MPI::Finalize(); 85 | return 0; 86 | } 87 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/openmp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(target MCoMP) 2 | 3 | set(srcs 4 | Implementations/OpenMPAlgo.cpp 5 | ) 6 | 7 | find_package(OpenMP) 8 | 9 | if (NOT OPENMP_FOUND) 10 | message(SEND_ERROR 11 | "Could not find a compatible OpenMP compiler. Consider turning BUILD_OPENMP to OFF") 12 | endif() 13 | 14 | add_executable(${target} main.cpp ${srcs}) 15 | 16 | target_link_libraries(${target} mantevo_marching_cubes_common) 17 | target_compile_options(${target} PUBLIC ${OpenMP_CXX_FLAGS}) 18 | set_target_properties(${target} PROPERTIES LINK_FLAGS ${OpenMP_CXX_FLAGS}) 19 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/openmp/Implementations/OpenMPAlgo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SerialAlgo.h 3 | * 4 | * Created on: Aug 17, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef IMPLEMENTATIONS_OPENMPALGO_H_ 9 | #define IMPLEMENTATIONS_OPENMPALGO_H_ 10 | 11 | // External includes 12 | #include"../../common/includes.h" 13 | 14 | // Reporting Headers 15 | #include"../../common/Reporting/YAML_Element.hpp" 16 | #include"../../common/Reporting/YAML_Doc.hpp" 17 | #include"../../common/Reporting/Log.h" 18 | 19 | // Strategy base class 20 | #include"../../common/Algorithm/MarchAlgorithm.h" 21 | #include"../../common/GeneralContext/GeneralContext.h" 22 | 23 | // Algorithm objects 24 | #include"../../common/Algorithm/Ranges.h" 25 | 26 | template 27 | class OpenMPAlgo : public MarchAlgorithm { 28 | public: 29 | OpenMPAlgo(); 30 | OpenMPAlgo(unsigned); 31 | virtual ~OpenMPAlgo(); 32 | 33 | unsigned numBlocks(const Range oneDRange); 34 | void march(GeneralContext &); 35 | private: 36 | unsigned grainDim; 37 | }; 38 | 39 | #endif /* IMPLEMENTATIONS_OPENMPALGO_H_ */ 40 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/openmp/Makefile: -------------------------------------------------------------------------------- 1 | # ----------------------------------------------- 2 | # Mantevo Marching Cubes OpenMP Implementation 3 | # 4 | # Author: sjmunn@sandia.gov 5 | # Date : 2015-07-31 6 | # 7 | # Changelog : 8 | # 2015-07-31 - created 9 | # ----------------------------------------------- 10 | 11 | # ========== Macros ============================= 12 | 13 | # project name (generate executable with this name) 14 | TARGET = MCoMP.exe 15 | 16 | # Compiler and flags 17 | CC = g++ 18 | CXXFLAGS = -O2 -fopenmp -std=c++0x 19 | #CXXFLAGS = -O0 -g -fopenmp -std=c++0x 20 | 21 | # Source and build directories 22 | SRCDIRS = Algorithm Implementations User_Interface 23 | BUILD_DIRECTORY = build 24 | BUILDDIR = $(BUILD_DIRECTORY) 25 | 26 | # Utility object code 27 | UTILS_DIR = ../common/build 28 | 29 | # Get source code files and generate object names 30 | SOURCES := $(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.cpp)) 31 | OBJECTS := $(addprefix $(BUILDDIR)/,$(notdir $(SOURCES:.cpp=.o))) 32 | UTILS_OBJ := $(wildcard $(UTILS_DIR)/*.o) 33 | 34 | # ========== Compiler Rules ===================== 35 | 36 | # Linker commands 37 | 38 | all: main.o $(OBJECTS) $(UTILS_OBJ) 39 | @echo "Linking object files..."; 40 | @$(CC) $(CXXFLAGS) $(BUILDDIR)/main.o $(OBJECTS) $(UTILS_OBJ) -o $(BUILDDIR)/$(TARGET); 41 | @echo "Compiled and linked "$(BUILDDIR)/$(TARGET)" successfully!" 42 | 43 | # Compiler commands 44 | 45 | main.o: main.cpp 46 | @mkdir -p $(BUILDDIR); 47 | @echo "Compiling "$(BUILDDIR)/$@; 48 | @$(CC) $(CXXFLAGS) -c main.cpp -o $(BUILDDIR)/$@; 49 | 50 | # General purpose object code compiler 51 | $(BUILDDIR)/%.o: ./*/%.cpp 52 | @mkdir -p $(BUILDDIR); 53 | @echo "Compiling "$@; 54 | @$(CC) $(CXXFLAGS) -c $< -o $@; 55 | 56 | # ========== Cleanup Rules ====================== 57 | 58 | .PHONEY: clean 59 | clean: 60 | rm -f $(BUILDDIR)/*.o; 61 | 62 | .PHONEY: clean_run_data 63 | clean_run_data: 64 | rm -f yaml_out.*; 65 | rm -f callgrind.*; 66 | 67 | .PHONEY: deepclean 68 | deepclean: clean clean_run_data 69 | rm -rf $(BUILDDIR); 70 | 71 | # ========== Debug Rules ======================== 72 | 73 | debug: 74 | @echo "Using compiler: " 75 | @echo $(CC) 76 | @echo "With flags: " 77 | @echo $(CXXFLAGS) 78 | @echo "Source code directories: " 79 | @echo $(SRCDIRS); 80 | @echo "Source code files: " 81 | @echo $(SOURCES); 82 | @echo "Object files: " 83 | @echo $(OBJECTS); 84 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/openmp/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * main.cpp 3 | * 4 | * Created on: Jul 2, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | // Common utility headers ------------- 9 | // Standard C/C++ library 10 | #include"../common/includes.h" 11 | 12 | // File i/o 13 | #include"../common/IO/LoadImage3DMPI.h" 14 | #include"../common/IO/SaveTriangleMesh.h" 15 | 16 | // Reporting 17 | #include"../common/Reporting/YAML_Element.hpp" 18 | #include"../common/Reporting/YAML_Doc.hpp" 19 | #include"../common/Reporting/Log.h" 20 | #include"../common/Reporting/Timer.h" 21 | 22 | #include"../common/User_Interface/UI.h" 23 | 24 | // Data Objects 25 | #include"../common/types.h" 26 | 27 | // Local implementation headers ------- 28 | // Algorithm 29 | #include"./Implementations/OpenMPAlgo.h" 30 | 31 | int main(int argc, char* argv[]) { 32 | 33 | LOG::ReportingLevel() = logDEBUG1; // Debug level is hard coded 34 | 35 | // Initialize the user interface 36 | UI mainUI(argc,argv); 37 | 38 | // Create data object 39 | GeneralContext data; 40 | 41 | LoadImage3DMPI fileHeader; 42 | fileHeader.loadHeader(mainUI.getFile()); 43 | fileHeader.setSperateData(mainUI.getDataFile()); 44 | 45 | LoadImage3DMPI fileData(fileHeader); // We will need multiple data loaders in MPI 46 | fileData.readEntireVolumeData(data.imageIn); 47 | 48 | // Report file data characteristics 49 | CLOG(logYAML) << "Volume image data file path: " << mainUI.getFile(); 50 | data.doc.add("Volume image data file path", mainUI.getFile()); 51 | fileHeader.report(data.doc); 52 | 53 | // Start the clock 54 | Timer RunTime; 55 | // Execute the marching cubes implementation 56 | data.isoval=mainUI.getIsoVal(); 57 | OpenMPAlgo algorithm; 58 | data.setAlgorithm(&algorithm); 59 | data.march(); 60 | // Stop Clock 61 | RunTime.stop(); 62 | 63 | //Report and save YAML file 64 | RunTime.reportTime(data.doc); 65 | data.doc.generateYAML(); 66 | 67 | // Save the result 68 | saveTriangleMesh(&(data.mesh), mainUI.outFile()); 69 | return 0; 70 | } 71 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/serial/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(target MCSerial) 2 | 3 | set(srcs 4 | Implementations/SerialAlgo.cpp 5 | ) 6 | 7 | add_executable(${target} main.cpp ${srcs}) 8 | 9 | target_link_libraries(${target} mantevo_marching_cubes_common) 10 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/serial/Implementations/SerialAlgo.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SerialAlgo.cpp 3 | * 4 | * Created on: Aug 17, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #include "SerialAlgo.h" 9 | 10 | template 11 | SerialAlgo::SerialAlgo() { 12 | // TODO Auto-generated constructor stub 13 | 14 | } 15 | 16 | template 17 | SerialAlgo::~SerialAlgo() { 18 | // TODO Auto-generated destructor stub 19 | } 20 | 21 | template 22 | void SerialAlgo::march(GeneralContext &data) { 23 | 24 | const unsigned *dims = data.imageIn.getDimension(); 25 | 26 | CLOG(logYAML) << "Marching cubes algorithm: SERIAL"; 27 | data.doc.add("Marching cubes algorithm", "SERIAL"); 28 | 29 | unsigned grainDim = dims[0]; // This doesn't matter 30 | 31 | Range3D cellRange(0, dims[2] - 1, grainDim, 0, dims[1] - 1, grainDim, 0, 32 | dims[0] - 1, grainDim); 33 | cellRange.extent(data.ext); 34 | 35 | this->setGlobalVariables(data); 36 | 37 | // The block is simply the full data extent 38 | MarchAlgorithm::extractIsosurfaceFromBlock(data.imageIn, data.ext, 39 | data.isoval, this->globalPointMap, *(this->globalEdgeIndices), data.mesh); 40 | } 41 | 42 | // Must instantiate class for separate compilation 43 | template class SerialAlgo ; 44 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/serial/Implementations/SerialAlgo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SerialAlgo.h 3 | * 4 | * Created on: Aug 17, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | #ifndef IMPLEMENTATIONS_SERIALALGO_H_ 9 | #define IMPLEMENTATIONS_SERIALALGO_H_ 10 | 11 | // External includes 12 | #include"../../common/includes.h" 13 | 14 | // Reporting Headers 15 | #include"../../common/Reporting/YAML_Element.hpp" 16 | #include"../../common/Reporting/YAML_Doc.hpp" 17 | #include"../../common/Reporting/Log.h" 18 | 19 | // Strategy base class 20 | #include"../../common/Algorithm/MarchAlgorithm.h" 21 | #include"../../common/GeneralContext/GeneralContext.h" 22 | 23 | // Algorithm objects 24 | #include"../../common/Algorithm/Ranges.h" 25 | 26 | template 27 | class SerialAlgo : public MarchAlgorithm { 28 | public: 29 | SerialAlgo(); 30 | virtual ~SerialAlgo(); 31 | 32 | void march(GeneralContext &); 33 | }; 34 | 35 | #endif /* IMPLEMENTATIONS_SERIALALGO_H_ */ 36 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/serial/Makefile: -------------------------------------------------------------------------------- 1 | # ----------------------------------------------- 2 | # Mantevo Marching Cubes Serial Implementation 3 | # 4 | # Author: sjmunn@sandia.gov 5 | # Date : 2015-07-31 6 | # 7 | # Changelog : 8 | # 2015-07-31 - created 9 | # ----------------------------------------------- 10 | 11 | # ========== Macros ============================= 12 | 13 | # project name (generate executable with this name) 14 | TARGET = MCSerial 15 | 16 | # Compiler and flags 17 | CC = g++ 18 | CXXFLAGS = -O2 -lrt -std=c++0x 19 | #CXXFLAGS = -O0 -g -lrt -std=c++0x 20 | 21 | # Linker and flags 22 | LINKER = g++ 23 | LINK_FLAGS = -Wl -lrt 24 | 25 | # Source and build directories 26 | SRCDIRS = Algorithm Implementations User_Interface 27 | BUILD_DIRECTORY = build 28 | BUILDDIR = $(BUILD_DIRECTORY) 29 | 30 | # Utility object code 31 | UTILS_DIR = ../common/build 32 | 33 | # Get source code files and generate object names 34 | SOURCES := $(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.cpp)) 35 | OBJECTS := $(addprefix $(BUILDDIR)/,$(notdir $(SOURCES:.cpp=.o))) 36 | UTILS_OBJ := $(wildcard $(UTILS_DIR)/*.o) 37 | 38 | # ========== Compiler Rules ===================== 39 | 40 | # Linker commands 41 | 42 | all: main.o $(OBJECTS) $(UTILS_OBJ) 43 | @echo "Linking object files..."; 44 | @$(LINKER) $(LINK_FLAGS) $(BUILDDIR)/main.o $(OBJECTS) $(UTILS_OBJ) -o $(BUILDDIR)/$(TARGET); 45 | @echo "Compiled and linked "$(BUILDDIR)/$(TARGET)" successfully!" 46 | 47 | #all: main.o $(OBJECTS) $(UTILS_OBJ) 48 | # @echo "Linking object files..."; 49 | # @$(LINKER) $(CXXFLAGS) $(BUILDDIR)/main.o $(OBJECTS) $(UTILS_OBJ) -o $(BUILDDIR)/$(TARGET); 50 | # @echo "Compiled and linked "$(BUILDDIR)/$(TARGET)" successfully!" 51 | 52 | # Compiler commands 53 | 54 | main.o: main.cpp 55 | @mkdir -p $(BUILDDIR); 56 | @echo "Compiling "$(BUILDDIR)/$@; 57 | @$(CC) $(CXXFLAGS) -c main.cpp -o $(BUILDDIR)/$@; 58 | 59 | # General purpose object code compiler 60 | $(BUILDDIR)/%.o: ./*/%.cpp 61 | @mkdir -p $(BUILDDIR); 62 | @echo "Compiling "$@; 63 | @$(CC) $(CXXFLAGS) -c $< -o $@; 64 | 65 | # ========== Cleanup Rules ====================== 66 | 67 | .PHONEY: clean 68 | clean: 69 | rm -f $(BUILDDIR)/*.o; 70 | 71 | .PHONEY: clean_run_data 72 | clean_run_data: 73 | rm -f yaml_out.*; 74 | rm -f callgrind.*; 75 | 76 | .PHONEY: deepclean 77 | deepclean: clean clean_run_data 78 | rm -rf $(BUILDDIR); 79 | 80 | # ========== Debug Rules ======================== 81 | 82 | debug: 83 | @echo "Using compiler: " 84 | @echo $(CC) 85 | @echo "With flags: " 86 | @echo $(CXXFLAGS) 87 | @echo "Source code directories: " 88 | @echo $(SRCDIRS); 89 | @echo "Source code files: " 90 | @echo $(SOURCES); 91 | @echo "Object files: " 92 | @echo $(OBJECTS); 93 | -------------------------------------------------------------------------------- /marchingCubes/obsolete/serial/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * main.cpp 3 | * 4 | * Created on: Jul 2, 2015 5 | * Author: sjmunn 6 | */ 7 | 8 | // Common utility headers ------------- 9 | // Standard C/C++ library 10 | #include"../common/includes.h" 11 | 12 | // File i/o 13 | #include"../common/IO/LoadImage3DMPI.h" 14 | #include"../common/IO/SaveTriangleMesh.h" 15 | 16 | // Reporting 17 | #include"../common/Reporting/YAML_Element.hpp" 18 | #include"../common/Reporting/YAML_Doc.hpp" 19 | #include"../common/Reporting/Log.h" 20 | #include"../common/Reporting/Timer.h" 21 | 22 | #include"../common/User_Interface/UI.h" 23 | 24 | // Context data 25 | #include"../common/GeneralContext/GeneralContext.h" 26 | 27 | // Local implementation headers ------- 28 | // Algorithm 29 | #include"./Implementations/SerialAlgo.h" 30 | 31 | int main(int argc, char* argv[]) { 32 | 33 | LOG::ReportingLevel() = logDEBUG1; // Debug level is hard coded 34 | 35 | // Initialize the user interface 36 | UI mainUI(argc,argv); 37 | 38 | // Create data object 39 | GeneralContext data; 40 | 41 | LoadImage3DMPI fileHeader; 42 | fileHeader.loadHeader(mainUI.getFile()); 43 | fileHeader.setSperateData(mainUI.getDataFile()); 44 | 45 | LoadImage3DMPI fileData(fileHeader); // We will need multiple data loaders in MPI 46 | fileData.readEntireVolumeData(data.imageIn); 47 | 48 | // Report file data characteristics 49 | CLOG(logYAML) << "Volume image data file path: " << mainUI.getFile(); 50 | data.doc.add("Volume image data file path", mainUI.getFile()); 51 | fileHeader.report(data.doc); 52 | 53 | // Start the clock 54 | Timer RunTime; 55 | // Execute the marching cubes implementation 56 | data.isoval=mainUI.getIsoVal(); 57 | SerialAlgo algorithm; 58 | data.setAlgorithm(&algorithm); 59 | data.march(); 60 | // Stop Clock 61 | RunTime.stop(); 62 | 63 | //Report and save YAML file 64 | RunTime.reportTime(data.doc); 65 | data.doc.generateYAML(); 66 | 67 | // Save the result 68 | saveTriangleMesh(&(data.mesh), mainUI.outFile()); 69 | return 0; 70 | } 71 | -------------------------------------------------------------------------------- /marchingCubes/openmp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 2 | # See LICENSE.txt for details. 3 | 4 | # Copyright (c) 2017 5 | # National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 6 | # the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 7 | # certain rights in this software. 8 | 9 | set(target openmp) 10 | 11 | set(srcs 12 | ../util/Image3D.cpp 13 | ../util/Timer.cpp 14 | ../mantevoCommon/YAML_Element.cpp 15 | ../mantevoCommon/YAML_Doc.cpp 16 | ) 17 | 18 | find_package(OpenMP) 19 | 20 | if (NOT OPENMP_FOUND) 21 | message(SEND_ERROR 22 | "Could not find a compatible OpenMP compiler. Consider turning BUILD_OPENMP to OFF") 23 | endif() 24 | 25 | add_executable(${target} main.cpp ${srcs}) 26 | 27 | target_compile_options(${target} PUBLIC ${OpenMP_CXX_FLAGS}) 28 | set_target_properties(${target} PROPERTIES LINK_FLAGS ${OpenMP_CXX_FLAGS}) 29 | 30 | -------------------------------------------------------------------------------- /marchingCubes/openmp/README.md: -------------------------------------------------------------------------------- 1 | ## openmp ## 2 | 3 | The openmp executable contains an extra argument from the reference 4 | implementation, the grianDim size. The grain_dim size controls the 5 | granularity of the parallel work. Example usage with an isovalue of 1.0 and 6 | grain_dim size of 1012: 7 | 8 | ``` 9 | export OMP_NUM_THREADS=n 10 | ./openmp/openmp -input_file myImage.vtk -output_file outputMeshOpenMP.vtk \ 11 | -isoval 1.0 -grain_dim 1012 12 | ``` 13 | 14 | This version of the implementation uses openMP to speed up the algorithm. 15 | The image is split up into uniform sections. Each openMP thread completes 16 | the algorithm over a number of sections and then the result is combine to 17 | create one output mesh. 18 | 19 | If two openMP threads have triangles that contain a point on the same edge, 20 | then that point will appear twice in the output mesh. The `openmpDupFree` 21 | implementation removes duplicate points. 22 | 23 | 24 | ## License ## 25 | 26 | miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 27 | See [LICENSE.txt](../../LICENSE.txt) for details. 28 | 29 | Copyright (c) 2017 30 | National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 31 | the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 32 | certain rights in this software. 33 | -------------------------------------------------------------------------------- /marchingCubes/openmpAndMpi/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 2 | # See LICENSE.txt for details. 3 | 4 | # Copyright (c) 2017 5 | # National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 6 | # the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 7 | # certain rights in this software. 8 | 9 | set(target openmpAndMpi) 10 | 11 | set(srcs 12 | ../util/Image3D.cpp 13 | ../util/Timer.cpp 14 | ../mantevoCommon/YAML_Element.cpp 15 | ../mantevoCommon/YAML_Doc.cpp 16 | ) 17 | 18 | find_package(MPI) 19 | 20 | if (NOT MPI_CXX_FOUND) 21 | message(SEND_ERROR 22 | "Could not find a compatible MPI compiler. Consider turning BUILD_MPI to OFF") 23 | endif() 24 | 25 | find_package(OpenMP) 26 | 27 | if (NOT OPENMP_FOUND) 28 | message(SEND_ERROR 29 | "Could not find a compatible OpenMP compiler. Consider turning BUILD_OPENMP to OFF") 30 | endif() 31 | 32 | 33 | add_executable(${target} main.cpp ${srcs}) 34 | 35 | target_include_directories(${target} 36 | PUBLIC "${MPI_CXX_INCLUDE_PATH}" 37 | ) 38 | target_compile_options(${target} 39 | PUBLIC ${OpenMP_CXX_FLAGS} ${MPI_CXX_COMPILE_FLAGS} 40 | ) 41 | target_link_libraries(${target} 42 | ${MPI_CXX_LIBRARIES} 43 | ) 44 | set_target_properties(${target} 45 | PROPERTIES LINK_FLAGS "${OpenMP_CXX_FLAGS} ${MPI_CXX_LINK_FLAGS}" 46 | ) 47 | -------------------------------------------------------------------------------- /marchingCubes/openmpAndMpi/README.md: -------------------------------------------------------------------------------- 1 | # openmpAndMpi # 2 | 3 | mpirun can be used to launch this executable. The -np flag tells mpi how 4 | many processes to run. 5 | 6 | ``` 7 | mpirun -np numProcesses ./openmpAndMpi/openmpAndMpi -i myImage.vtk \ 8 | -o outputMeshOpenmpAndMpi -v 1.0 -g 1012 9 | ``` 10 | 11 | This implementation is a combination of the `openmpDupFree` and `mpi` 12 | implementations. It uses both mpi and openmp to speed up the algorithm. 13 | 14 | 15 | ## License ## 16 | 17 | miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 18 | See [LICENSE.txt](../../LICENSE.txt) for details. 19 | 20 | Copyright (c) 2017 21 | National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 22 | the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 23 | certain rights in this software. 24 | -------------------------------------------------------------------------------- /marchingCubes/openmpDupFree/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 2 | # See LICENSE.txt for details. 3 | 4 | # Copyright (c) 2017 5 | # National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 6 | # the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 7 | # certain rights in this software. 8 | 9 | set(target openmpDupFree) 10 | 11 | set(srcs 12 | ../util/Image3D.cpp 13 | ../util/Timer.cpp 14 | ../mantevoCommon/YAML_Element.cpp 15 | ../mantevoCommon/YAML_Doc.cpp 16 | ) 17 | 18 | find_package(OpenMP) 19 | 20 | if (NOT OPENMP_FOUND) 21 | message(SEND_ERROR 22 | "Could not find a compatible OpenMP compiler. Consider turning BUILD_OPENMP to OFF") 23 | endif() 24 | 25 | add_executable(${target} main.cpp ${srcs}) 26 | 27 | target_compile_options(${target} PUBLIC ${OpenMP_CXX_FLAGS}) 28 | set_target_properties(${target} PROPERTIES LINK_FLAGS ${OpenMP_CXX_FLAGS}) 29 | 30 | -------------------------------------------------------------------------------- /marchingCubes/openmpDupFree/README.md: -------------------------------------------------------------------------------- 1 | ## openmpDupFree ## 2 | 3 | When parallel versions are run, points along the boundaries may be 4 | accounted for multiple times. This version is the same as openmp except it 5 | removes those duplicate points. 6 | 7 | ``` 8 | export OMP_NUM_THREADS=n 9 | ./openmp/openmp -i myImage.vtk -o outputMeshOpenMP.vtk -v 1.0 -g 1012 10 | ``` 11 | 12 | This version of the implementation uses openMP to speed up the algorithm. 13 | The image is split up into uniform sections. Each openMP thread completes 14 | the algorithm over a number of sections and then the result is combine to 15 | create one output mesh. Unlike the `openmp` implementation, the output mesh 16 | of this implementation guarantees that there are no duplicate points. 17 | 18 | 19 | ## License ## 20 | 21 | miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 22 | See [LICENSE.txt](../../LICENSE.txt) for details. 23 | 24 | Copyright (c) 2017 25 | National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 26 | the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 27 | certain rights in this software. 28 | -------------------------------------------------------------------------------- /marchingCubes/reference: -------------------------------------------------------------------------------- 1 | serial/ -------------------------------------------------------------------------------- /marchingCubes/serial/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 2 | # See LICENSE.txt for details. 3 | 4 | # Copyright (c) 2017 5 | # National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 6 | # the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 7 | # certain rights in this software. 8 | 9 | set(target serial) 10 | 11 | set(srcs 12 | ../util/Image3D.cpp 13 | ../util/Timer.cpp 14 | ../mantevoCommon/YAML_Element.cpp 15 | ../mantevoCommon/YAML_Doc.cpp 16 | ) 17 | 18 | add_executable(${target} main.cpp ${srcs}) 19 | 20 | 21 | -------------------------------------------------------------------------------- /marchingCubes/serial/README.md: -------------------------------------------------------------------------------- 1 | ## serial ## 2 | 3 | Example usage with an isovalue of 1.0: 4 | 5 | ``` 6 | ./serial/serial -input_file myImage.vtk -output_file outputMeshSerial.vtk \ 7 | -isoval 1.0 8 | ``` 9 | 10 | This is the reference implementation. The algorithm is executed without any 11 | parallelization. 12 | 13 | 14 | ## License ## 15 | 16 | miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 17 | See [LICENSE.txt](../../LICENSE.txt) for details. 18 | 19 | Copyright (c) 2017 20 | National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 21 | the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 22 | certain rights in this software. 23 | -------------------------------------------------------------------------------- /marchingCubes/util/ConvertBuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ConvertBuffer.h 3 | * 4 | * Created on: Jul 6, 2015 5 | * Author: sjmunn 6 | * 7 | * miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 8 | * See LICENSE.txt for details. 9 | * 10 | * Copyright (c) 2017 11 | * National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 12 | * the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 13 | * certain rights in this software. 14 | */ 15 | 16 | #ifndef UTIL_CONVERTBUFFER_H_ 17 | #define UTIL_CONVERTBUFFER_H_ 18 | 19 | #include "TypeInfo.h" 20 | #include "Errors.h" 21 | 22 | namespace util 23 | { 24 | template 25 | inline void flipEndianness(T &val) 26 | { 27 | int mid = sizeof(T) / 2; 28 | char *data = reinterpret_cast(&val); 29 | for (int i = 0; i < mid; ++i) { 30 | std::swap(data[i], data[sizeof(T) - i - 1]); 31 | } 32 | } 33 | 34 | template 35 | void convertBuffer(const SrcT *in, std::size_t nelms, DstT *out) 36 | { 37 | for (std::size_t i = 0; i < nelms; ++i) 38 | { 39 | SrcT val = *in++; 40 | flipEndianness(val); 41 | *out++ = static_cast(val); 42 | } 43 | } 44 | 45 | template 46 | void convertBufferWithTypeInfo( 47 | const char *in, const TypeInfo &ti, std::size_t nelms, T *out) 48 | { 49 | switch (ti.getId()) { 50 | case TypeInfo::ID_CHAR: 51 | convertBuffer(in, nelms, out); 52 | break; 53 | case TypeInfo::ID_SHORT: 54 | convertBuffer(reinterpret_cast(in), nelms, out); 55 | break; 56 | case TypeInfo::ID_USHORT: 57 | convertBuffer(reinterpret_cast(in), nelms, out); 58 | break; 59 | case TypeInfo::ID_INT: 60 | convertBuffer(reinterpret_cast(in), nelms, out); 61 | break; 62 | case TypeInfo::ID_FLOAT: 63 | convertBuffer(reinterpret_cast(in), nelms, out); 64 | break; 65 | case TypeInfo::ID_DOUBLE: 66 | convertBuffer(reinterpret_cast(in), nelms, out); 67 | break; 68 | //default: 69 | // throw no_type("Data type is not supported"); 70 | // break; 71 | } 72 | } 73 | } // util namespace 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /marchingCubes/util/Errors.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Errors.h 3 | * 4 | * Created on: Jul 6, 2015 5 | * Author: sjmunn 6 | * 7 | * miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 8 | * See LICENSE.txt for details. 9 | * 10 | * Copyright (c) 2017 11 | * National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 12 | * the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 13 | * certain rights in this software. 14 | */ 15 | 16 | #ifndef IO_ERRORS_H_ 17 | #define IO_ERRORS_H_ 18 | 19 | #include 20 | #include 21 | 22 | using std::size_t; 23 | 24 | namespace util { 25 | 26 | class file_not_found: public std::exception { 27 | public: 28 | file_not_found(const char* const inFileName) : 29 | fileName(inFileName) { 30 | 31 | std::cout << "file_not_found " << inFileName << std::endl; 32 | std::cout << "Given Path: " << fileName << std::endl; 33 | } 34 | 35 | private: 36 | const char* const fileName; 37 | }; 38 | 39 | class bad_format: public std::exception { 40 | public: 41 | bad_format(const char* const inMessage) : 42 | message(inMessage) { 43 | std::cout << "bad_format error with message: " << inMessage << std::endl; 44 | } 45 | 46 | private: 47 | const char* const message; 48 | }; 49 | 50 | class no_type: public std::exception { 51 | public: 52 | no_type(const char* const inMessage) : 53 | message(inMessage) { 54 | std::cout << "Type not defined error with message: " << inMessage << std::endl; 55 | } 56 | 57 | private: 58 | const char* const message; 59 | }; 60 | 61 | class not_enough_memory_allocated: public std::exception { 62 | public: 63 | not_enough_memory_allocated(const char* const inMessage) : 64 | message(inMessage) { 65 | std::cout << "Not enough memory allocated: " << inMessage << std::endl; 66 | } 67 | private: 68 | const char* const message; 69 | }; 70 | 71 | } // util namespace 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /marchingCubes/util/Timer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Timer.cpp 3 | * 4 | * Created on: Jul 17, 2015 5 | * Author: sjmunn 6 | * 7 | * miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 8 | * See LICENSE.txt for details. 9 | * 10 | * Copyright (c) 2017 11 | * National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 12 | * the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 13 | * certain rights in this software. 14 | */ 15 | 16 | #include "Timer.h" 17 | 18 | #include 19 | 20 | namespace util { 21 | 22 | Timer::Timer() { 23 | start(); 24 | } 25 | 26 | void Timer::getCurrentTimeValues(TimeValue_t &ticksCPU, 27 | TimeValue_t &wallSeconds, 28 | TimeValue_t &wallNanoseconds) const { 29 | ticksCPU = clock(); 30 | 31 | #if (_POSIX_TIMERS > 0) && (_POSIX_MONOTONIC_CLOCK > 0) 32 | struct timespec currentTime; 33 | clock_gettime(CLOCK_MONOTONIC, ¤tTime); 34 | wallSeconds = currentTime.tv_sec; 35 | wallNanoseconds = currentTime.tv_nsec; 36 | #else 37 | struct timeval currentTime; 38 | gettimeofday(¤tTime, NULL); 39 | wallSeconds = currentTime.tv_sec; 40 | wallNanoseconds = currentTime.tv_usec * 1000; 41 | #endif 42 | } 43 | 44 | void Timer::start() { 45 | totalWallTime=0; 46 | totalCPUtime=0; 47 | totalTicksCPU=0; 48 | 49 | resume(); 50 | } 51 | 52 | void Timer::pause(void) { 53 | TimeValue_t currentTicksCPU, currentWallSeconds, currentWallNanoseconds; 54 | getCurrentTimeValues(currentTicksCPU, 55 | currentWallSeconds, 56 | currentWallNanoseconds); 57 | 58 | totalTicksCPU = currentTicksCPU-startTicksCPU; 59 | totalCPUtime += (static_cast(totalTicksCPU))/CLOCKS_PER_SEC; 60 | 61 | totalWallTime += (currentWallSeconds - startWallSeconds); 62 | totalWallTime += 63 | (currentWallNanoseconds - startWallNanoseconds) / 1000000000.0; 64 | } 65 | 66 | void Timer::resume(void) { 67 | getCurrentTimeValues(startTicksCPU, startWallSeconds, startWallNanoseconds); 68 | } 69 | 70 | void Timer::stop(void) { 71 | pause(); 72 | } 73 | 74 | Timer::~Timer() { 75 | // TODO Auto-generated destructor stub 76 | } 77 | 78 | } // util namespace 79 | -------------------------------------------------------------------------------- /marchingCubes/util/Timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Timer.h 3 | * 4 | * Created on: Jul 17, 2015 5 | * Author: sjmunn 6 | * 7 | * miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 8 | * See LICENSE.txt for details. 9 | * 10 | * Copyright (c) 2017 11 | * National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 12 | * the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 13 | * certain rights in this software. 14 | */ 15 | 16 | #ifndef REPORTING_TIMER_H_ 17 | #define REPORTING_TIMER_H_ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | namespace util { 24 | 25 | class Timer { 26 | public: 27 | Timer(); 28 | //Timer(bool); 29 | virtual ~Timer(); 30 | 31 | //void startForProcess(void); 32 | 33 | void start(void); 34 | 35 | void pause(void); 36 | void resume(void); 37 | 38 | void stop(void); 39 | 40 | double getTotalTicks(void) const { return totalTicksCPU; } 41 | double getWallTime(void) const { return totalWallTime; } 42 | double getCPUtime(void) const { return totalCPUtime; } 43 | 44 | private: 45 | typedef long long TimeValue_t; 46 | 47 | TimeValue_t startTicksCPU; 48 | TimeValue_t startWallSeconds; 49 | TimeValue_t startWallNanoseconds; 50 | double totalWallTime; 51 | double totalCPUtime; 52 | TimeValue_t totalTicksCPU; 53 | 54 | void getCurrentTimeValues(TimeValue_t &ticksCPU, 55 | TimeValue_t &wallSeconds, 56 | TimeValue_t &wallNanoseconds) const; 57 | }; 58 | 59 | } // util namespace 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /marchingCubes/util/TriangleMesh.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TriangleMesh.h 3 | * 4 | * Created on: Jan 13, 2017 5 | * Author: dbourge 6 | * 7 | * miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 8 | * See LICENSE.txt for details. 9 | * 10 | * Copyright (c) 2017 11 | * National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 12 | * the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 13 | * certain rights in this software. 14 | */ 15 | 16 | #ifndef TRIANGLEMESH_H_ 17 | #define TRIANGLEMESH_H_ 18 | 19 | #include 20 | #include 21 | 22 | namespace util { 23 | 24 | template 25 | class TriangleMesh 26 | { 27 | public: 28 | using PointIterator = 29 | typename std::vector >::const_iterator; 30 | using NormalIterator = 31 | typename std::vector >::const_iterator; 32 | using TriangleIterator = 33 | typename std::vector >::const_iterator; 34 | 35 | TriangleMesh() 36 | {} 37 | 38 | TriangleMesh( 39 | std::vector > points, 40 | std::vector > normals, 41 | std::vector > indexTriangles) 42 | : points(points), 43 | normals(normals), 44 | indexTriangles(indexTriangles) 45 | {} 46 | 47 | std::size_t numberOfVertices() const 48 | { 49 | return points.size(); 50 | } 51 | 52 | std::size_t numberOfTriangles() const 53 | { 54 | return indexTriangles.size(); 55 | } 56 | 57 | PointIterator pointsBegin() const 58 | { 59 | return points.begin(); 60 | } 61 | 62 | PointIterator pointsEnd() const 63 | { 64 | return points.end(); 65 | } 66 | 67 | NormalIterator normalsBegin() const 68 | { 69 | return normals.begin(); 70 | } 71 | 72 | NormalIterator normalsEnd() const 73 | { 74 | return normals.end(); 75 | } 76 | 77 | TriangleIterator trianglesBegin() const 78 | { 79 | return indexTriangles.begin(); 80 | } 81 | 82 | TriangleIterator trianglesEnd() const 83 | { 84 | return indexTriangles.end(); 85 | } 86 | 87 | private: 88 | std::vector > points; 89 | std::vector > normals; 90 | std::vector > indexTriangles; 91 | }; 92 | 93 | } 94 | 95 | #endif 96 | -------------------------------------------------------------------------------- /marchingCubes/util/TypeInfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TypeInfo.h 3 | * 4 | * Created on: Jan 18, 2017 5 | * Author: dbourge, sjmunn 6 | * 7 | * miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 8 | * See LICENSE.txt for details. 9 | * 10 | * Copyright (c) 2017 11 | * National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 12 | * the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 13 | * certain rights in this software. 14 | */ 15 | 16 | #ifndef __TypeInfo_h 17 | #define __TypeInfo_h 18 | 19 | #include 20 | 21 | namespace util 22 | { 23 | static const char *names[] = { "unknown", "char", "short", "unsigned_short", 24 | "int", "float", "double" }; 25 | static const size_t sizes[] = { 0, 1, 2, 2, 4, 4, 8 }; 26 | 27 | 28 | class TypeInfo { 29 | public: 30 | enum TypeId { 31 | ID_UNKNOWN = 0, 32 | ID_CHAR, 33 | ID_SHORT, 34 | ID_USHORT, 35 | ID_INT, 36 | ID_FLOAT, 37 | ID_DOUBLE, 38 | NUM_TYPES 39 | }; 40 | 41 | TypeInfo() 42 | : id(TypeId::ID_UNKNOWN) 43 | {} 44 | 45 | TypeInfo(TypeId inId) 46 | : id(inId) 47 | {} 48 | 49 | TypeInfo(const char * typeName) 50 | : id(getTypeId(typeName)) 51 | {} 52 | 53 | TypeId getId() const { 54 | return id; 55 | } 56 | 57 | const char* name() const { 58 | return names[id]; 59 | } 60 | 61 | size_t size() const { 62 | return sizes[id]; 63 | } 64 | 65 | static TypeId getTypeId(const char *name) { 66 | std::string nm(name); 67 | for (int i = 1; i < TypeInfo::NUM_TYPES; ++i) { 68 | if (nm == names[i]) { 69 | return TypeId(i); 70 | } 71 | } 72 | return ID_UNKNOWN; 73 | } 74 | 75 | private: 76 | TypeId id; 77 | }; 78 | 79 | template 80 | TypeInfo createTemplateTypeInfo() { 81 | return TypeInfo(TypeInfo::ID_UNKNOWN); 82 | } 83 | 84 | template<> 85 | TypeInfo createTemplateTypeInfo() { 86 | return TypeInfo(TypeInfo::ID_CHAR); 87 | } 88 | 89 | template<> 90 | TypeInfo createTemplateTypeInfo() { 91 | return TypeInfo(TypeInfo::ID_SHORT); 92 | } 93 | 94 | template<> 95 | TypeInfo createTemplateTypeInfo() { 96 | return TypeInfo(TypeInfo::ID_SHORT); 97 | } 98 | 99 | template<> 100 | TypeInfo createTemplateTypeInfo() { 101 | return TypeInfo(TypeInfo::ID_INT); 102 | } 103 | 104 | template<> 105 | TypeInfo createTemplateTypeInfo() { 106 | return TypeInfo(TypeInfo::ID_FLOAT); 107 | } 108 | 109 | template<> 110 | TypeInfo createTemplateTypeInfo() { 111 | return TypeInfo(TypeInfo::ID_DOUBLE); 112 | } 113 | 114 | } 115 | 116 | #endif 117 | -------------------------------------------------------------------------------- /marchingCubes/util/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * util.h 3 | * 4 | * miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 5 | * See LICENSE.txt for details. 6 | * 7 | * Copyright (c) 2017 8 | * National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 9 | * the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 10 | * certain rights in this software. 11 | */ 12 | 13 | #ifndef UTIL_UTIL_UTIL 14 | #define UTIL_UTIL_UTIL 15 | 16 | #include 17 | 18 | #include "MarchingCubesTables.h" 19 | 20 | namespace util 21 | { 22 | static const int caseMask[] = {1, 2, 4, 8, 16, 32, 64, 128}; 23 | 24 | template 25 | int 26 | findCaseId(std::array const& cubeVertexVals, T const& isoval) 27 | { 28 | int caseId=0; 29 | for(int i = 0; i < 8; ++i) 30 | { 31 | // Note that util::caseMask[i] = {1, 2, 4, 8, 16, 32, 64, 128} 32 | // Example: 33 | // Suppose caseId = 3, i = 4 and cubeVertexVals[4] >= isoval. 34 | // Then caseId will be set to caseId | 16. In terms of bits, 35 | // caseId = 11000000 | 00001000 = 11001000 = 19 36 | if(cubeVertexVals[i] >= isoval) 37 | { 38 | caseId |= caseMask[i]; 39 | } 40 | } 41 | return caseId; 42 | } 43 | 44 | template 45 | std::array 46 | interpolate(std::array const& a, std::array const& b, T weight) 47 | { 48 | std::array ret; 49 | for(int i = 0; i != N; ++i) 50 | { 51 | ret[i] = a[i] + (weight * (b[i] - a[i])); 52 | } 53 | return ret; 54 | } 55 | 56 | struct Indexer 57 | { 58 | Indexer(size_t const& nTotal, size_t const& nSections) 59 | : grain(nTotal / nSections), 60 | split((grain+1)*nSections - nTotal) 61 | {} 62 | 63 | size_t operator()(size_t const& idx) const 64 | { 65 | if(idx <= split) 66 | { 67 | return grain*idx; 68 | } 69 | else 70 | { 71 | return grain*split + (grain+1)*(idx-split); 72 | } 73 | } 74 | 75 | private: 76 | size_t const grain; 77 | size_t const split; 78 | }; 79 | } 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /utilities/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 2 | # See LICENSE.txt for details. 3 | 4 | # Copyright (c) 2017 5 | # National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 6 | # the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 7 | # certain rights in this software. 8 | 9 | cmake_minimum_required(VERSION 2.8.12) 10 | set(CMAKE_CXX_STANDARD 11) 11 | 12 | project(miniIsosurfaceUtilities) 13 | 14 | 15 | add_subdirectory(tests) 16 | add_subdirectory(dataGen) 17 | 18 | -------------------------------------------------------------------------------- /utilities/dataGen/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 2 | # See LICENSE.txt for details. 3 | 4 | # Copyright (c) 2017 5 | # National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 6 | # the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 7 | # certain rights in this software. 8 | 9 | set(target dataGen) 10 | 11 | set(srcs 12 | open-simplex-noise.c 13 | ) 14 | 15 | add_executable(${target} main.cpp ${srcs}) 16 | 17 | 18 | -------------------------------------------------------------------------------- /utilities/dataGen/open-simplex-noise.h: -------------------------------------------------------------------------------- 1 | #ifndef OPEN_SIMPLEX_NOISE_H__ 2 | #define OPEN_SIMPLEX_NOISE_H__ 3 | 4 | /* 5 | * OpenSimplex (Simplectic) Noise in C. 6 | * Ported to C from Kurt Spencer's java implementation by Stephen M. Cameron 7 | * 8 | * v1.1 (October 6, 2014) 9 | * - Ported to C 10 | * 11 | * v1.1 (October 5, 2014) 12 | * - Added 2D and 4D implementations. 13 | * - Proper gradient sets for all dimensions, from a 14 | * dimensionally-generalizable scheme with an actual 15 | * rhyme and reason behind it. 16 | * - Removed default permutation array in favor of 17 | * default seed. 18 | * - Changed seed-based constructor to be independent 19 | * of any particular randomization library, so results 20 | * will be the same when ported to other languages. 21 | * 22 | * Copyright (c) DoD HPCMP PETTT. All rights reserved. 23 | * See LICENSE file for details. 24 | * New copyright, applies to all modifications since the original copyright. 25 | * 26 | * Original Copyright: 27 | * This is free and unencumbered software released into the public domain. 28 | */ 29 | 30 | #if ((__GNUC_STDC_INLINE__) || (__STDC_VERSION__ >= 199901L)) 31 | #include 32 | #define INLINE inline 33 | #elif (defined (_MSC_VER) || defined (__GNUC_GNU_INLINE__)) 34 | #include 35 | #define INLINE __inline 36 | #else 37 | /* ANSI C doesn't have inline or stdint.h. */ 38 | #define INLINE 39 | #endif 40 | 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif 44 | 45 | struct osn_context; 46 | 47 | int open_simplex_noise(int64_t seed, struct osn_context **ctx); 48 | void open_simplex_noise_free(struct osn_context *ctx); 49 | int open_simplex_noise_init_perm(struct osn_context *ctx, int16_t p[], int nelements); 50 | double open_simplex_noise2(struct osn_context *ctx, double x, double y); 51 | double open_simplex_noise3(struct osn_context *ctx, double x, double y, double z); 52 | double open_simplex_noise4(struct osn_context *ctx, double x, double y, double z, double w); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /utilities/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 2 | # See LICENSE.txt for details. 3 | 4 | # Copyright (c) 2017 5 | # National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 6 | # the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 7 | # certain rights in this software. 8 | 9 | set(target SameContentsCheck) 10 | 11 | add_executable(${target} SameContentsCheck.cpp) 12 | 13 | -------------------------------------------------------------------------------- /utilities/tests/README.md: -------------------------------------------------------------------------------- 1 | # SameContentsCheck # 2 | 3 | There are multiple ways that an output mesh can be represented. To check 4 | that two output files from mantevo-marching-cubes have equivalent meshes, 5 | use SameContentsCheck: 6 | 7 | ``` 8 | ./tests/SameContentsCheck outputMeshSerial.vtk outputMeshOpenMP.vtk 9 | ``` 10 | 11 | 12 | ## License ## 13 | 14 | miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 15 | See [LICENSE.txt](../../LICENSE.txt) for details. 16 | 17 | Copyright (c) 2017 18 | National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 19 | the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 20 | certain rights in this software. 21 | -------------------------------------------------------------------------------- /vtkReference/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 2 | # See LICENSE.txt for details. 3 | 4 | # Copyright (c) 2017 5 | # National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 6 | # the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 7 | # certain rights in this software. 8 | 9 | cmake_minimum_required(VERSION 2.8) 10 | 11 | PROJECT(vtkReference) 12 | 13 | find_package(VTK REQUIRED) 14 | include(${VTK_USE_FILE}) 15 | 16 | set(srcs 17 | ../marchingCubes/util/Timer.cpp 18 | ../marchingCubes/mantevoCommon/YAML_Element.cpp 19 | ../marchingCubes/mantevoCommon/YAML_Doc.cpp 20 | ) 21 | 22 | add_executable(vtkReference MACOSX_BUNDLE main.cpp ${srcs}) 23 | 24 | if(VTK_LIBRARIES) 25 | target_link_libraries(vtkReference ${VTK_LIBRARIES}) 26 | else() 27 | target_link_libraries(vtkReference vtkHybrid vtkWidgets) 28 | endif() 29 | -------------------------------------------------------------------------------- /vtkReference/README.md: -------------------------------------------------------------------------------- 1 | ## VTK Reference Implementation ## 2 | 3 | Example usage with an isovalue of 1.0: 4 | 5 | ``` 6 | ./vtk/vtk -input_file myImage.vtk -output_file outputMeshSerial.vtk \ 7 | -isoval 1.0 -algorithm mc 8 | ``` 9 | 10 | This is an implementation that uses VTK to run either marching cubes or 11 | flying edges. Any parallelization that occurs comes from VTK. The VTK 12 | library must be linked. 13 | 14 | # Build Instructuions # 15 | 16 | ``` 17 | cmake /path/to/miniIsusurface/vtkReference -DVTK_DIR:PATH=/path/to/vtk/build 18 | make 19 | ``` 20 | 21 | 22 | ## License ## 23 | 24 | miniIsosurface is distributed under the OSI-approved BSD 3-clause License. 25 | See [LICENSE.txt](../LICENSE.txt) for details. 26 | 27 | Copyright (c) 2017 28 | National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under 29 | the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 30 | certain rights in this software. 31 | --------------------------------------------------------------------------------