Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • iMSTK/VegaFEM-CMake
  • ben.boeckel/vegafem-cmake
2 results
Show changes
Commits on Source (11)
Showing
with 302 additions and 189 deletions
find_path(ARPACK_INCLUDE_DIR
argsym.h
/usr/local/ARPACK/arpack++/include)
find_library(ARPACK_LIB arpack_SUN4
/usr/local/ARPACK)
set(ARPACK_LIBRARIES ${ARPACK_LIB})
......@@ -4,87 +4,57 @@
# MKLSOLVER_LIBRARIES - List of fully qualified libraries to link against.
# MKLSOLVER_FOUND - Do not attempt to use if "no" or undefined.
set(INTEL_MKL_YEAR 2011)
set(INTEL_MKL_YEAR 2020)
set(INTEL_MKL_ARCH intel64)
find_path(INTEL_MKL_INCLUDE_DIR
mkl_blas.h
"C:/Program Files/Intel/ComposerXE-${INTEL_MKL_YEAR}/mkl/include"
/opt/intel/composerxe-${INTEL_MKL_YEAR}/mkl/include
/opt/intel/compilers_and_libraries_${INTEL_MKL_YEAR}/linux/mkl/include
)
# set(LIB_MKL_LIST mkl_intel_ilp64 mkl_intel_thread mkl_core mkl_solver_ilp64 mkl_mc mkl_mc3 mkl_lapack PTHREAD mkl_p4n iomp5)
find_library(MKL_INTEL_ILP64 mkl_intel_ilp64
find_library(MKL_INTEL_LP64 mkl_intel_lp64
"C:/Program Files/Intel/ComposerXE-${INTEL_MKL_YEAR}/mkl/lib/${INTEL_MKL_ARCH}"
/opt/intel/composerxe-${INTEL_MKL_YEAR}/mkl/lib/${INTEL_MKL_ARCH}
)
if(CMAKE_COMPILER_IS_GNUCXX )
find_library(MKL_THREAD mkl_gnu_thread
"C:/Program Files/Intel/ComposerXE-${INTEL_MKL_YEAR}/mkl/lib/${INTEL_MKL_ARCH}"
/opt/intel/composerxe-${INTEL_MKL_YEAR}/mkl/lib/${INTEL_MKL_ARCH}
)
else(CMAKE_COMPILER_IS_GNUCXX )
find_library(MKL_THREAD mkl_intel_thread
/opt/intel/compilers_and_libraries_${INTEL_MKL_YEAR}/linux/mkl/lib/${INTEL_MKL_ARCH}
)
# if(CMAKE_COMPILER_IS_GNUCXX )
# find_library(MKL_THREAD mkl_gnu_thread
# "C:/Program Files/Intel/ComposerXE-${INTEL_MKL_YEAR}/mkl/lib/${INTEL_MKL_ARCH}"
# /opt/intel/compilers_and_libraries_${INTEL_MKL_YEAR}/linux/mkl/lib/${INTEL_MKL_ARCH}
# )
# else(CMAKE_COMPILER_IS_GNUCXX )
# find_library(MKL_THREAD mkl_intel_thread
# "C:/Program Files/Intel/ComposerXE-${INTEL_MKL_YEAR}/mkl/lib/${INTEL_MKL_ARCH}"
# /opt/intel/compilers_and_libraries_${INTEL_MKL_YEAR}/linux/mkl/lib/${INTEL_MKL_ARCH}
# )
# endif(CMAKE_COMPILER_IS_GNUCXX )
find_library(MKL_THREAD mkl_intel_thread
"C:/Program Files/Intel/ComposerXE-${INTEL_MKL_YEAR}/mkl/lib/${INTEL_MKL_ARCH}"
/opt/intel/composerxe-${INTEL_MKL_YEAR}/mkl/lib/${INTEL_MKL_ARCH}
)
endif(CMAKE_COMPILER_IS_GNUCXX )
find_library(MKL_CORE mkl_core
"C:/Program Files/Intel/ComposerXE-${INTEL_MKL_YEAR}/mkl/lib/${INTEL_MKL_ARCH}"
/opt/intel/composerxe-${INTEL_MKL_YEAR}/mkl/lib/${INTEL_MKL_ARCH}
)
find_library(MKL_SOLVER_ILP64 mkl_solver_ilp64
"C:/Program Files/Intel/ComposerXE-${INTEL_MKL_YEAR}/mkl/lib/${INTEL_MKL_ARCH}"
/opt/intel/composerxe-${INTEL_MKL_YEAR}/mkl/lib/${INTEL_MKL_ARCH}
/opt/intel/compilers_and_libraries_${INTEL_MKL_YEAR}/linux/mkl/lib/${INTEL_MKL_ARCH}
)
find_library(MKL_MC mkl_mc
"C:/Program Files/Intel/ComposerXE-${INTEL_MKL_YEAR}/mkl/lib/${INTEL_MKL_ARCH}"
/opt/intel/composerxe-${INTEL_MKL_YEAR}/mkl/lib/${INTEL_MKL_ARCH}
)
find_library(MKL_MC3 mkl_mc3
"C:/Program Files/Intel/ComposerXE-${INTEL_MKL_YEAR}/mkl/lib/${INTEL_MKL_ARCH}"
/opt/intel/composerxe-${INTEL_MKL_YEAR}/mkl/lib/${INTEL_MKL_ARCH}
)
find_library(MKL_LAPACK mkl_lapack
"C:/Program Files/Intel/ComposerXE-${INTEL_MKL_YEAR}/mkl/lib/${INTEL_MKL_ARCH}"
/opt/intel/composerxe-${INTEL_MKL_YEAR}/mkl/lib/${INTEL_MKL_ARCH}
)
find_library(MKL_P4N mkl_p4n
find_library(MKL_CORE mkl_core
"C:/Program Files/Intel/ComposerXE-${INTEL_MKL_YEAR}/mkl/lib/${INTEL_MKL_ARCH}"
/opt/intel/composerxe-${INTEL_MKL_YEAR}/mkl/lib/${INTEL_MKL_ARCH}
/opt/intel/compilers_and_libraries_${INTEL_MKL_YEAR}/linux/mkl/lib/${INTEL_MKL_ARCH}
)
set(INTEL_MKL_LIBRARIES ${MKL_P4N} ${MKL_MC3} ${MKL_MC} ${MKL_LAPACK} ${MKL_SOLVER_ILP64} ${MKL_CORE} ${MKL_THREAD} ${MKL_INTEL_ILP64})
set(INTEL_MKL_LIBRARIES m ${MKL_INTEL_LP64} ${MKL_THREAD} ${MKL_CORE} iomp5 gfortran)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(MKL
REQUIRED_VARS
INTEL_MKL_INCLUDE_DIR
MKL_P4N
MKL_MC3
MKL_MC
MKL_LAPACK
MKL_SOLVER_ILP64
MKL_CORE
MKL_INTEL_LP64
MKL_THREAD
MKL_INTEL_ILP64
MKL_CORE
)
mark_as_advanced(
INTEL_MKL_INCLUDE_DIR
MKL_P4N
MKL_MC3
MKL_MC
MKL_LAPACK
MKL_SOLVER_ILP64
MKL_CORE
MKL_INTEL_LP64
MKL_THREAD
MKL_INTEL_ILP64
MKL_CORE
)
find_path(PTHREAD_INCLUDE_DIR
pthread.h
)
set(PTHREAD_INCLUDE_DIR ${PTHREAD_INCLUDE_DIR})
find_library(PTHREAD_RELEASE_LIBRARY
NAMES
pthread
libpthread
)
if (EXISTS ${PTHREAD_RELEASE_LIBRARY})
list(APPEND PTHREAD_LIBRARIES optimized ${PTHREAD_RELEASE_LIBRARY})
endif()
find_library(PTHREAD_DEBUG_LIBRARY
NAMES
pthreadd
libpthreadd
)
if (EXISTS ${PTHREAD_DEBUG_LIBRARY})
list(APPEND PTHREAD_LIBRARIES debug ${PTHREAD_DEBUG_LIBRARY})
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(PTHREAD
REQUIRED_VARS
PTHREAD_INCLUDE_DIR
PTHREAD_LIBRARIES)
mark_as_advanced(
PTHREAD_INCLUDE_DIR
PTHREAD_DEBUG_LIBRARY
PTHREAD_RELEASE_LIBRARY)
if(PTHREAD_FOUND AND NOT TARGET Threads::Threads)
add_library(Threads::Threads INTERFACE IMPORTED)
target_include_directories(Threads::Threads INTERFACE "${PTHREAD_INCLUDE_DIR}")
if (EXISTS ${PTHREAD_DEBUG_LIBRARY})
target_link_libraries(Threads::Threads INTERFACE debug ${PTHREAD_DEBUG_LIBRARY})
endif()
if (EXISTS ${PTHREAD_RELEASE_LIBRARY})
target_link_libraries(Threads::Threads INTERFACE optimized ${PTHREAD_RELEASE_LIBRARY})
endif()
endif()
# Add access to dependencies Find<package>.cmake files
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/CMake)
set(VegaFEM_ENABLE_PTHREADS_SUPPORT @VegaFEM_ENABLE_PTHREADS_SUPPORT@)
if(VegaFEM_ENABLE_PTHREADS_SUPPORT)
if(WIN32)
find_package(PThreads REQUIRED)
else()
find_package(Threads REQUIRED)
endif()
endif()
# Remove access to those dependencies
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/CMake)
include("${CMAKE_CURRENT_LIST_DIR}/VegaFEMTargets.cmake")
......@@ -3,82 +3,172 @@ project(VegaFEM)
set(VegaFEM_VERSION 4.0)
# Minimum required version of CMake
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.5)
if(COMMAND CMAKE_POLICY)
cmake_policy(SET CMP0003 NEW)
cmake_policy(SET CMP0079 NEW)
cmake_policy(SET CMP0072 OLD)
if (POLICY CMP0022)
# Use INTERFACE_LINK_LIBRARIES when available.
cmake_policy(SET CMP0022 NEW)
endif()
if (POLICY CMP0042)
cmake_policy(SET CMP0042 NEW)
endif()
endif(COMMAND CMAKE_POLICY)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake")
include(VegaFEMMacros)
# Add Options
option(VegaFEM_BUILD_UTILITIES "Build utility classes in addition to libraries." OFF)
option(VegaFEM_BUILD_UTILITIES "Build utility classes in addition to libraries." ON)
option(VegaFEM_BUILD_MODEL_REDUCTION "Build model-reduction" ON)
option(VegaFEM_BUILD_MODEL_REDUCTION "Build model-reduction" OFF)
option(VegaFEM_BUILD_IMMERSION_MESHER "Build immersion-mesher" OFF)
option(VegaFEM_BUILD_RIGID_BODIES "Build Rigid body support" OFF)
option(VegaFEM_ENABLE_OpenGL_SUPPORT "Should modules that require OpenGL be enabled?" ON)
option(VegaFEM_ENABLE_PTHREADS_SUPPORT "Use multithreading (pthread)" ON)
option(VegaFEM_ENABLE_ExpoKit_SUPPORT "Should matrix classes use ExpoKit for exponentiation?" OFF)
# TODO: define USE_EXPOKIT if enabled
option(VegaFEM_ENABLE_OpenGL_SUPPORT "Should modules that require OpenGL be enabled?" ON)
option(VegaFEM_ENABLE_CLOTH_SUPPORT "Should modules that require OpenGL be enabled?" ON)
if (VegaFEM_ENABLE_OpenGL_SUPPORT)
add_definitions( -DENABLE_OpenGL )
endif()
if (VegaFEM_ENABLE_OpenGL_SUPPORT)
# Only add Cg support if OpenGL is turned on. This may change in the future.
option(VegaFEM_ENABLE_Cg_SUPPORT "Should modules that require Cg be enabled?" ON)
endif()
if(NOT VegaFEM_ENABLE_OpenGL_SUPPORT)
set(VegaFEM_BUILD_UTILITIES OFF CACHE STRING "utilities cannot be build without OPENGL" FORCE)
endif()
if (VegaFEM_ENABLE_OpenGL_SUPPORT AND VegaFEM_BUILD_UTILITIES)
find_package(GLUI)
if(NOT GLUI_FOUND)
add_subdirectory(thirdparty/glui/2.36/src)
add_subdirectory(libraries/glui/glui-2.35/src)
set(GLUI_LIBRARY glui)
set(GLUI_INCLUDE_DIR) # Empty this as library will export its own includes.
endif()
endif()
set(VegaFEM_MODULES
animationHelper
basicAlgorithms
clothBW
configFile
constrainedDOFs
corotationalLinearFEM
distanceField
elasticForceModel
exactArithmetic
forceModel
getopts
glslPhong
graph
hashTable
imageIO
immersionMesher
integrator
integratorSparse
interpolationCoordinates
isotropicHyperelasticFEM
laplacianMatrix
libiglInterface
listIO
massSpringSystem
matrixIO
mesh
mesher
minivector
objMesh
performanceCounter
polarDecomposition
quaternion
sceneObject
shapeEdit
sparseMatrix
sparseSolver
stencilForceModel
stvk
virtualTets
volumetricMesh
windingNumber
set(CMAKE_SKIP_BUILD_RPATH FALSE)
# when building, don't use the install RPATH already
# (but later on when installing)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
# the RPATH/INSTALL_NAME_DIR to be used when installing
if (NOT APPLE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib:\$ORIGIN/../lib")
endif(NOT APPLE)
# On OSX, we need to set INSTALL_NAME_DIR instead of RPATH
# http://www.cmake.org/cmake/help/cmake-2-8-docs.html#variable:CMAKE_INSTALL_NAME_DIR
set(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib")
# add the automatically determined parts of the RPATH which point to
# directories outside the build tree to the install RPATH
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
if (VegaFEM_ENABLE_OpenGL_SUPPORT)
find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
find_package(GLEW REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR})
include_directories(${GLUT_INCLUDE_DIR})
include_directories(${GLEW_INCLUDE_DIR})
if (GLUT_FOUND AND APPLE)
mark_as_advanced(GLUT_cocoa_LIBRARY)
endif()
if (VegaFEM_ENABLE_Cg_SUPPORT)
find_package(Cg REQUIRED)
mark_as_advanced(
CG_COMPILER
CG_GL_LIBRARY
CG_INCLUDE_PATH
CG_LIBRARY
)
endif()
endif()
if (VegaFEM_BUILD_MODEL_REDUCTION)
if (NOT APPLE)
find_package(MKL)
if(MKL_FOUND)
set(BLA_VENDOR "Intel mkl")
include_directories(${INTEL_MKL_INCLUDE_DIR})
# TODO: set option for the paradiso solvers and define PARDISO_SOLVER_IS_AVAILABLE
add_definitions( -DPARDISO_SOLVER_IS_AVAILABLE)
else()
find_package(LAPACKE REQUIRED) # Also searches for cblas
find_package(LAPACK REQUIRED)
# find_package(CBLAS REQUIRED)
find_package(BLAS REQUIRED)
include_directories(${LAPACKE_INCLUDE_DIR})
include_directories(${LAPACK_INCLUDE_DIR})
include_directories(${CBLAS_INCLUDE_DIR})
include_directories(${BLAS_INCLUDE_DIR})
endif()
find_package(ARPACK REQUIRED)
include_directories(${ARPACK_INCLUDE_DIR})
endif()
endif()
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/libraries/include)
set(VegaFEM_Modules
basicAlgorithms
clothBW
configFile
constrainedDOFs
corotationalLinearFEM
distanceField
elasticForceModel
forceModel
getopts
graph
hashTable
imageIO
integrator
integratorSparse
interpolationCoordinates
isotropicHyperelasticFEM
laplacianMatrix
listIO
massSpringSystem
# matrix
matrixIO
mesh
minivector
objMesh
# openGLHelper
performanceCounter
polarDecomposition
quaternion
# shapeEdit
sparseMatrix
sparseSolver
stencilForceModel
stvk
volumetricMesh
windingNumber
)
# include_directories(include)
if (VegaFEM_BUILD_MODEL_REDUCTION)
set(VegaFEM_Modules
${VegaFEM_Modules}
......@@ -88,15 +178,30 @@ if (VegaFEM_BUILD_MODEL_REDUCTION)
reducedElasticForceModel
reducedForceModel
reducedStvk
shapeEdit
)
endif()
if (VegaFEM_BUILD_IMMERSION_MESHER)
set(VegaFEM_Modules
${VegaFEM_Modules}
mesher
immersionMesher
virtualTets
libiglInterface
exactArithmetic
)
endif()
if (VegaFEM_ENABLE_OpenGL_SUPPORT)
set(VegaFEM_Modules
${VegaFEM_Modules}
animationHelper
camera
glslPhong
lighting
openGLHelper
sceneObject
glslPhong
)
if (VegaFEM_ENABLE_Cg_SUPPORT)
set(VegaFEM_Modules
......@@ -107,7 +212,6 @@ if (VegaFEM_ENABLE_OpenGL_SUPPORT)
if (VegaFEM_BUILD_MODEL_REDUCTION)
set(VegaFEM_Modules
${VegaFEM_Modules}
openGLHelper
sceneObjectReduced
renderVolumetricMesh
)
......@@ -115,8 +219,13 @@ if (VegaFEM_ENABLE_OpenGL_SUPPORT)
endif()
add_subdirectory(libraries)
if(VegaFEM_BUILD_UTILITIES)
add_subdirectory(utilities)
endif(VegaFEM_BUILD_UTILITIES)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/VegaFEMConfigVersion.cmake"
......@@ -124,10 +233,19 @@ write_basic_package_version_file(
COMPATIBILITY AnyNewerVersion
)
export(EXPORT VegaFEMTargets
FILE "${CMAKE_CURRENT_BINARY_DIR}/VegaFEMTargets.cmake"
export(PACKAGE VegaFEM)
export(TARGETS ${VegaFEM_Modules}
FILE "${CMAKE_CURRENT_BINARY_DIR}/VegaFEM/VegaFEMTargets.cmake"
NAMESPACE VegaFEM::
)
# export(EXPORT VegaFEMTargets
# FILE "${CMAKE_CURRENT_BINARY_DIR}/VegaFEMTargets.cmake"
# NAMESPACE VegaFEM::
# )
configure_file(
CMake/VegaFEMConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/VegaFEMConfig.cmake"
......@@ -154,6 +272,3 @@ install(
)
if(VegaFEM_BUILD_UTILITIES)
add_subdirectory(utilities)
endif(VegaFEM_BUILD_UTILITIES)
......@@ -8,7 +8,7 @@ vega_add_library(animationHelper
handleScript.h
simulationRecorder.h
)
target_link_libraries(camera
target_link_libraries(animationHelper
PUBLIC
${OPENGL_LIBRARIES}
matrixIO
......
......@@ -33,8 +33,12 @@
#include "handleControl.h"
#include "openGLHelper.h"
#include <iostream>
using namespace std;
namespace vega
{
void HandleControl::setMouseButtonActivity(bool mouseDown, bool mouseOnObject, bool buildNewHandle, Vec3d worldPos, float zValue,
function<int()> getClosestExistingHandle, function<pair<int,bool>()> addOrRemoveHandle)
{
......@@ -119,3 +123,5 @@ void HandleControl::renderHandle(SphericalCamera * camera, const Vec3d & handleP
handleRender.render(handlePosition);
}
} // namespace vega
......@@ -39,6 +39,9 @@
#include <functional>
namespace vega
{
class HandleControl
{
public:
......@@ -73,4 +76,6 @@ protected:
};
} // namespace vega
#endif
......@@ -36,8 +36,12 @@
#include <string>
#include <sstream>
#include <cassert>
using namespace std;
namespace vega
{
const string HandleScript::commandName[HandleScript::NUM_COMMANDS] = {
"VOID",
"ADD",
......@@ -183,3 +187,5 @@ bool HandleScript::save(const char * filename)
fout.close();
return true;
}
} // namespace vega
......@@ -37,6 +37,9 @@
#include <vector>
#include <string>
namespace vega
{
// a simple class to load/save a script of handle creation/deletion/movement
class HandleScript
......@@ -74,4 +77,6 @@ protected:
};
} // namespace vega
#endif
......@@ -34,8 +34,12 @@
#include <iostream>
#include <cstdio>
#include "matrixIO.h"
using namespace std;
namespace vega
{
FrameRecorder::FrameRecorder(int size, const std::string & fn, int mf, int numSkippedIntervalFrames) :
r(size), numFrames(0), filename(fn), maxFrames(mf), saved(false), numSkipIter(numSkippedIntervalFrames+1), skipCounter(numSkipIter) {}
......@@ -64,11 +68,11 @@ bool FrameRecorder::save()
printf("Writing %d frames into %s... ", numFrames, filename.c_str());
int ret = WriteMatrixToDisk(filename.c_str(), r, numFrames, &u[0]);
if(ret == 0) {
cout << "Done." << endl;
std::cout << "Done." << endl;
saved = true;
return true;
}
cout << "Failed." << endl;
std::cout << "Failed." << endl;
return false;
}
......@@ -110,3 +114,5 @@ void SimulationRecorder::clear()
vFrames.clear();
fFrames.clear();
}
} // namespace vega
......@@ -36,6 +36,9 @@
#include <string>
#include <vector>
namespace vega
{
// record frames of data and save to disk
class FrameRecorder
{
......@@ -99,4 +102,6 @@ protected:
FrameRecorder uFrames, vFrames, fFrames;
};
} // namespace vega
#endif
......@@ -37,7 +37,11 @@
#include <cmath>
#include <algorithm>
#include "averagingBuffer.h"
using namespace std;
// using namespace std;
namespace vega
{
AveragingBuffer::AveragingBuffer(int size_) : size(size_), index(0)
{
......@@ -74,8 +78,8 @@ void AveragingBuffer::setBufferSize(int newSize)
return;
// create a new buffer, copy enough values from old buffer to the new buffer
vector<double> newBuffer(newSize);
int numToCopy = min(newSize, numValuesAdded); // max number of values that can be copied
std::vector<double> newBuffer(newSize);
int numToCopy = std::min(newSize, numValuesAdded); // max number of values that can be copied
for(int i = 0; i < numToCopy; i++)
index = (index + (size-1)) % size; // move index backward #numToCopy times
......@@ -94,3 +98,5 @@ void AveragingBuffer::setBufferSize(int newSize)
numValuesAdded = numToCopy;
average /= numValuesAdded;
}
} // namespace vega
......@@ -34,6 +34,9 @@
#define _AVERAGING_BUFFER_H_
#include <vector>
namespace vega
{
// FIFO averaging buffer
class AveragingBuffer
......@@ -59,5 +62,7 @@ protected:
int numValuesAdded; // #values stored in the buffer
};
} // namespace vega
#endif
......@@ -41,6 +41,11 @@
#include <vector>
#include <cmath>
using namespace std;
namespace vega
{
template<class Container>
int sizei(const Container & c) { return (int)c.size(); }
......@@ -225,4 +230,6 @@ ForwardIt reduceDuplicates(ForwardIt first, ForwardIt last, BinaryReduce reduce)
return reduceDuplicates(first, last ,reduce, std::equal_to<const T &>());
}
} // namespace vega
#endif
......@@ -31,8 +31,12 @@
*************************************************************************/
#include "containerHelper.h"
using namespace std;
namespace vega
{
template<class T>
bool saveToAscii(const std::vector<T> & v, std::ostream & out)
{
......@@ -74,3 +78,5 @@ template bool saveToAscii<double>(const std::vector<double> & v, std::ostream &
template bool loadFromAscii<int>(std::vector<int> & v, std::istream & in);
template bool loadFromAscii<double>(std::vector<double> & v, std::istream & in);
} // namespace vega
......@@ -43,6 +43,9 @@
#include <numeric>
#include <unordered_set>
namespace vega
{
/////////////////////////////////////////////////////
// Check element in set/map //
/////////////////////////////////////////////////////
......@@ -431,4 +434,6 @@ std::vector<T,A> findUniqueElements(const std::vector<T,A> vec, std::vector<int>
return ret;
}
} // namespace vega
#endif
......@@ -35,7 +35,11 @@
#include <iostream>
#include <cassert>
#include "disjointSet.h"
using namespace::std;
using namespace std;
namespace vega
{
void DisjointSet::makeSet(void)
{
......@@ -58,7 +62,7 @@ int DisjointSet::findSet(int x) const
{
if (x < 0 || x >= (int)(parent.size()))
{
cout << "Error in DisjointSet::findSet(int x): the x value is illegal." << endl;
std::cout << "Error in DisjointSet::findSet(int x): the x value is illegal." << std::endl;
exit(0);
}
int ancestor = x;
......@@ -79,12 +83,12 @@ void DisjointSet::unionSet(int x, int y)
int size = parent.size();
if (x < 0 || x >= size)
{
cout << "Error in DisjointSet::UnionSet(int x, int y): the x value is illegal." << endl;
std::cout << "Error in DisjointSet::UnionSet(int x, int y): the x value is illegal." << std::endl;
exit(0);
}
if (y < 0 || y >= size)
{
cout << "Error in DisjointSet::UnionSet(int x, int y): the y value is illegal." << endl;
std::cout << "Error in DisjointSet::UnionSet(int x, int y): the y value is illegal." << std::endl;
exit(0);
}
int ancestor1 = findSet(x);
......@@ -109,9 +113,9 @@ void DisjointSet::unionSet(int x, int y)
std::vector<int> DisjointSet::createOldToNewIDMapping()
{
vector<int> old2new(size());
std::vector<int> old2new(size());
int numNewIDs = 0;
vector<int> setRepID2newID(size(), -1);
std::vector<int> setRepID2newID(size(), -1);
for(int i = 0; i < size(); i++)
{
int repID = findSet(i); // first, store set representive IDs to old2new
......@@ -164,16 +168,16 @@ void DisjointSetDynamic::unionSet(int x, int y)
set.unionSet(setIDx, setIDy);
}
vector<vector<int>> DisjointSetDynamic::getAllSets() const
std::vector<std::vector<int>> DisjointSetDynamic::getAllSets() const
{
map<int, vector<int>> sets; // rep setID -> elementIDs
std::map<int, std::vector<int>> sets; // rep setID -> elementIDs
for(const auto & p : setID)
{
int eleID = p.first;
int setID = p.second;
sets[set.findSet(setID)].push_back(eleID);
}
vector<vector<int>> ret;
std::vector<std::vector<int>> ret;
for(auto & p : sets)
{
ret.emplace_back(move(p.second));
......@@ -181,3 +185,5 @@ vector<vector<int>> DisjointSetDynamic::getAllSets() const
return ret;
}
} // namespace vega
......@@ -48,6 +48,9 @@
#include <vector>
#include <map>
namespace vega
{
// implementation of a disjoint set on a fixed array of elements with continuous IDs
class DisjointSet
{
......@@ -128,4 +131,6 @@ void DisjointSet::unionRange(IntIterator itBegin, IntIterator itEnd)
unionSet(*itBegin, *jt);
}
} // namespace vega
#endif
......@@ -34,11 +34,15 @@
#include "stringHelper.h"
#include <cstring>
#include <iostream>
using namespace std;
namespace vega
{
int readEachLine(const std::string & filename, std::function<int(std::string & line)> processLine, const char * comment)
{
fstream fin(filename.c_str());
std::fstream fin(filename.c_str());
if (!fin) return 1;
return readEachLine(fin, processLine, comment);
}
......@@ -61,3 +65,5 @@ int readEachLine(std::istream & fin, std::function<int(std::string & line)> proc
}
return 0;
}
} // namespace vega