Initial commit

This commit is contained in:
iasonmanolas 2021-05-31 13:40:00 +03:00
commit 81a60c686c
5 changed files with 1606 additions and 0 deletions

61
CMakeLists.txt Executable file
View File

@ -0,0 +1,61 @@
cmake_minimum_required(VERSION 2.8)
project(PatternTillingReducedModel)
#Add the project cmake scripts to the module path
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
#Download external dependencies NOTE: If the user has one of these libs it shouldn't be downloaded again.
include(${CMAKE_MODULE_PATH}/DownloadProject.cmake)
if (CMAKE_VERSION VERSION_LESS 3.2)
set(UPDATE_DISCONNECTED_IF_AVAILABLE "")
else()
set(UPDATE_DISCONNECTED_IF_AVAILABLE "UPDATE_DISCONNECTED 1")
endif()
set(EXTERNAL_DEPS_DIR "/home/iason/Coding/build/external dependencies")
if(NOT EXISTS ${EXTERNAL_DEPS_DIR})
set(EXTERNAL_DEPS_DIR ${CMAKE_CURRENT_BINARY_DIR})
endif()
##Create directory for the external libraries
file(MAKE_DIRECTORY ${EXTERNAL_DEPS_DIR})
add_compile_definitions(ENABLE_OPENMP)
set(USE_POLYSCOPE TRUE)
if(${USE_POLYSCOPE})
##Polyscope
download_project(PROJ POLYSCOPE
GIT_REPOSITORY https://github.com/nmwsharp/polyscope.git
GIT_TAG master
PREFIX ${EXTERNAL_DEPS_DIR}
${UPDATE_DISCONNECTED_IF_AVAILABLE}
)
add_subdirectory(${POLYSCOPE_SOURCE_DIR} ${POLYSCOPE_BINARY_DIR})
add_compile_definitions(POLYSCOPE_DEFINED)
endif()
set(MYSOURCES_SOURCE_DIR "/home/iason/Coding/Libraries/MySources")
if (NOT EXISTS ${MYSOURCES_SOURCE_DIR})
##MySources
download_project(PROJ MYSOURCES
GIT_REPOSITORY https://gitea-s2i2s.isti.cnr.it/manolas/MySources.git
GIT_TAG master
PREFIX ${EXTERNAL_DEPS_DIR}
${UPDATE_DISCONNECTED_IF_AVAILABLE}
)
endif()
add_subdirectory(${MYSOURCES_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/MySourcesBinDir)
#Add the project sources
file(GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/*.hpp ${POLYSCOPE_SOURCE_DIR}/deps/imgui/imgui/misc/cpp/imgui_stdlib.cpp)
add_executable(${PROJECT_NAME} ${SOURCES} )
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20)
target_include_directories(${PROJECT_NAME}
PRIVATE ${MYSOURCES_SOURCE_DIR}
)
target_link_libraries(${PROJECT_NAME} polyscope MySources )

128
src/hexagonremesher.hpp Normal file
View File

@ -0,0 +1,128 @@
#ifndef HEXAGONREMESHER_HPP
#define HEXAGONREMESHER_HPP
#include "polymesh.hpp"
#include "vcgtrimesh.hpp"
#include <vcg/complex/algorithms/dual_meshing.h>
#include <vcg/complex/algorithms/isotropic_remeshing.h>
#include <vcg/complex/algorithms/point_sampling.h>
#include <vcg/complex/algorithms/polygon_support.h>
#include <vcg/complex/algorithms/polygonal_algorithms.h>
#include <vcg/complex/algorithms/voronoi_remesher.h>
namespace PolygonalRemeshing {
//std::shared_ptr<VCGPolyMesh>
std::shared_ptr<VCGPolyMesh> remeshWithPolygons(VCGTriMesh &surface)
{
// const std::string tileIntoFilePath(
// "/home/iason/Coding/build/PatternTillingReducedModel/RelWithDebInfo/plane.ply");
// const std::string tileIntoFilePath("/home/iason/Coding/build/PatternTillingReducedModel/"
// "RelWithDebInfo/hexagon.ply");
// const std::string tileIntoFilePath("/home/iason/Coding/build/PatternTillingReducedModel/"
// "RelWithDebInfo/instantMeshes_plane_34.ply");
// const std::string tileIntoFilePath("/home/iason/Coding/build/PatternTillingReducedModel/"
// "RelWithDebInfo/instantMeshes_plane.ply");
// assert(std::filesystem::exists(tileIntoFilePath));
// assert(tileInto_polyMesh.load(tileIntoFilePath));
///Load triangle mesh
// VCGTriMesh tileInto_triMesh;
// assert(std::filesystem::exists(tileIntoFilePath));
// tileInto_triMesh.load(tileIntoFilePath);
///Sample the triangle mesh
// std::vector<CoordType> pointVec;
// double radius = 1;
// int sampleNum = 50;
// // // vcg::tri::PoissonSampling<VCGTriMesh>(tileInto_triMesh, pointVec, sampleNum, radius);
// // // vcg::tri::TrivialSampler<VCGTriMesh> ps;
// // // vcg::tri::SurfaceSampling<VCGTriMesh>::VertexUniform(tileInto_triMesh, ps, sampleNum);
// // // pointVec = ps.SampleVec();
// vcg::tri::MontecarloSampling<VCGTriMesh>(tileInto_triMesh, pointVec, sampleNum);
// vcg::tri::VoronoiProcessingParameter vpp;
// vcg::tri::VoronoiProcessing<VCGTriMesh>::PreprocessForVoronoi(tileInto_triMesh, radius, vpp);
// std::vector<VCGTriMesh::VertexType *> seedVec;
// vcg::tri::VoronoiProcessing<VCGTriMesh>::SeedToVertexConversion(tileInto_triMesh,
// pointVec,
// seedVec);
// vcg::tri::EuclideanDistance<VCGTriMesh> df;
// vpp.geodesicRelaxFlag = false;
// const int iterNum = 100;
// int actualIter = vcg::tri::VoronoiProcessing<VCGTriMesh>::VoronoiRelaxing(tileInto_triMesh,
// seedVec,
// iterNum,
// df,
// vpp);
// std::cout << "Voronoi relaxation iterations performed:" << actualIter << std::endl;
// bool saveWasSuccessful
// = 0
// == vcg::tri::io::ExporterOBJ<VCGTriMesh>::Save(tileInto_triMesh,
// "./tileInto_triMesh.obj",
// vcg::tri::io::Mask::IOM_ALL);
// VCGTriMesh delaunay;
// vcg::tri::VoronoiProcessing<VCGTriMesh>::ConvertDelaunayTriangulationToMesh(tileInto_triMesh,
// delaunay,
// seedVec);
// delaunay.setLabel("Delaunay");
// delaunay.save(delaunay.getLabel() + ".ply");
// delaunay.registerForDrawing();
// ////Load surface
VCGPolyMesh tileInto_polyMesh, dual;
// vcg::tri::PolygonSupport<VCGTriMesh, VCGPolyMesh>::ImportFromTriMesh(tileInto_polyMesh,
// delaunay);
vcg::tri::PolygonSupport<VCGTriMesh, VCGPolyMesh>::ImportFromTriMesh(tileInto_polyMesh, surface);
vcg::tri::DualMeshing<VCGPolyMesh>::MakeDual(tileInto_polyMesh, dual, false);
// for(size_t i=0; i< Edges.size(); ++i)
// {
// std::vector<VCGPolyMesh> fpVec;
// std::vector<int> eiVec;
// face::EFStarFF(Edges[i].f,Edges[i].z,fpVec,eiVec);
// for(size_t j=0;j<fpVec.size();++j)
// fpVec[j]->FEp(eiVec[j])=&(m.edge[i]);
// }
dual.setLabel(surface.getLabel() + "_polyDual");
bool saveWasSuccessful
= 0
== vcg::tri::io::ExporterOBJ<VCGPolyMesh>::Save(dual,
(dual.getLabel() + ".obj").c_str(),
vcg::tri::io::Mask::IOM_BITPOLYGONAL);
assert(saveWasSuccessful);
vcg::tri::UpdateNormal<VCGPolyMesh>::PerFaceNormalized(dual);
// vcg::PolygonalAlgorithm<VCGPolyMesh>::SmoothReprojectPCA(dual, 1000, false, 0.5, 0, false, false);
// vcg::tri::io::ExporterOBJ<VCGPolyMesh>::Save(dual,
// "./dual_optimized.obj",
// vcg::tri::io::Mask::IOM_BITPOLYGONAL);
// if (vcg::tri::VoronoiProcessing<VCGTriMesh>::CheckVoronoiTopology(tileInto_triMesh, seedVec)) {
// VCGTriMesh voronoiMesh, voronoiPoly;
// vcg::tri::VoronoiProcessing<VCGTriMesh>::ConvertVoronoiDiagramToMesh(tileInto_triMesh,
// voronoiMesh,
// voronoiPoly,
// seedVec,
// vpp);
// vcg::tri::Allocator<VCGTriMesh>::CompactEveryVector(voronoiMesh);
// voronoiMesh.setLabel("Voro");
// voronoiMesh.save(voronoiMesh.getLabel() + ".ply");
// // voronoiMesh.registerForDrawing();
// vcg::tri::Allocator<VCGTriMesh>::CompactEveryVector(voronoiPoly);
// voronoiPoly.setLabel("Poly");
// voronoiPoly.save(voronoiPoly.getLabel() + ".ply");
// // voronoiPoly.registerForDrawing();
// // polyscope::show();
// }
// dual.registerForDrawing();
// polyscope::show();
// assert(vcg::tri::IsValidPointer(dual, dual.face[0].cFEp(0)));
return std::make_shared<VCGPolyMesh>(dual);
}
} // namespace PolygonalRemeshing
#endif // HEXAGONREMESHER_HPP

63
src/main.cpp Executable file
View File

@ -0,0 +1,63 @@
#include "edgemesh.hpp"
#include "hexagonremesher.hpp"
#include "polyscope/curve_network.h"
#include "polyscope/polyscope.h"
#include "polyscope/surface_mesh.h"
#include "reducedmodeloptimizer_structs.hpp"
#include "reducedpatternsimulator.hpp"
#include "simulationmesh.hpp"
#include "trianglepatterngeometry.hpp"
#include <iostream>
int main(int argc, char *argv[])
{
// DRMSimulationModel::runUnitTests();
// const std::string tileInto_triMesh_filename(
// "/home/iason/Coding/build/PatternTillingReducedModel/Meshes/"
// "instantMeshes_strip_45.ply");
// const std::string tileInto_triMesh_filename(
// "/home/iason/Coding/build/PatternTillingReducedModel/Meshes/"
// "instantMeshes_widerStrip_100.ply");
const std::string tileInto_triMesh_filename(
"/home/iason/Coding/build/PatternTillingReducedModel/Meshes/"
"instantMeshes_plane_34.ply");
// const std::string tileInto_triMesh_filename(
// "/home/iason/Coding/build/PatternTillingReducedModel/RelWithDebInfo/"
// "instantMeshes_plane4Hexagon_5.ply");
VCGTriMesh tileInto_triMesh;
tileInto_triMesh.load(tileInto_triMesh_filename);
std::shared_ptr<VCGPolyMesh> pTileInto_polyMesh = PolygonalRemeshing::remeshWithPolygons(
tileInto_triMesh);
//Load optimization results
// const size_t numberOfOptimizationResults = argc - 1;
// std::vector<ReducedPatternOptimization::Results> optimizationResults(
// numberOfOptimizationResults);
// for (size_t commandLineParameterIndex = 0;
// commandLineParameterIndex < numberOfOptimizationResults;
// commandLineParameterIndex++)
// optimizationResults[commandLineParameterIndex].load(argv[commandLineParameterIndex + 1]);
// for (const auto &dirEntry : std::filesystem::directory_iterator(
std::filesystem::path optimizationResultsPath0(
"/home/iason/Coding/build/ReducedModelOptimization/RelWithDebInfo/OptimizationResults/"
"ConvergedJobs");
std::filesystem::path optimizationResultsPath1(
"/home/iason/Coding/Projects/Approximating shapes with flat "
"patterns/ReducedModelOptimization/Results/selectionOfPatterns_0.2To1.6/"
"selectionOfPatterns/1.2/ConvergedJobs");
std::vector<ReducedPatternOptimization::Results> optimizationResults
= ReducedPatternSimulator::loadOptimizationResults(optimizationResultsPath1);
//Load reduced
const std::filesystem::path patternFilePath(
"/home/iason/Coding/Projects/Approximating shapes with flat "
"patterns/ReducedModelOptimization/TestSet/ReducedPatterns/single_reduced.ply");
PatternGeometry reducedPattern(patternFilePath.string());
reducedPattern.setLabel(std::filesystem::path(patternFilePath).stem().string());
PolyscopeInterface::init();
ReducedPatternSimulator reducedPatternSimulator(optimizationResults);
reducedPatternSimulator.simulate(pTileInto_polyMesh, optimizationResults, reducedPattern);
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,171 @@
#ifndef REDUCEDPATTERNSIMULATOR_HPP
#define REDUCEDPATTERNSIMULATOR_HPP
#include "reducedmodeloptimizer_structs.hpp"
#include "simulationmesh.hpp"
#include "trianglepatterngeometry.hpp"
#include "utilities.hpp"
using DRMFullSimulationResults = SimulationResults;
using LinearFullSimulationResults = SimulationResults;
using ReducedSimulationResults = SimulationResults;
using FullPatternVertexIndex = int;
using ReducedPatternVertexIndex = int;
class ReducedPatternSimulator
{
std::shared_ptr<SimulationMesh> pTiledFullPattern_simulationMesh;
std::shared_ptr<SimulationMesh> pTiledReducedPattern_simulationMesh;
std::shared_ptr<SimulationJob> pJob_tiledReducedPattern;
std::shared_ptr<SimulationJob> pJob_tiledFullPattern;
const Vector6d externalForce{0, 0, 0.1, 0, 0, 0};
double minInputForceMagnitude = std::numeric_limits<double>::max();
std::array<float, 3> gui_externalForce{0, 0, 0};
std::array<float, 3> gui_externalMoment{0, 0, 0};
std::array<float, 4> gui_randomnessParams{0.02, 0.02, 0.3, 0.4};
std::unordered_map<VertexIndex, VertexIndex> fullToReducedViMap; //of only the common vertices
std::unordered_map<VertexIndex, VertexIndex> reducedToFullViMap; //of only the common vertices
std::vector<size_t> tilledFullPatternInterfaceVi;
double surfaceBaseTriangleHeight{-1};
std::string fullPatternsSurfacelabel;
std::string fullPatternsLabel;
vcg::Triangle3<double> reducedPatternBaseTriangle;
PatternGeometry reducedPattern;
const bool randomTesselationIsEnabled{false};
const std::vector<std::string> scenariosTestSetLabels{// "22Hex_random0",
// "22Hex_random1",
// "22Hex_random2",
// "22Hex_random3",
// "22Hex_random4",
// "22Hex_random5",
// "22Hex_random6",
// "22Hex_random7",
// "22Hex_random8",
// "22Hex_random9",
// "22Hex_random10",
// "22Hex_random11",
// "22Hex_random12",
// "22Hex_random17",
// "22Hex_random14"
"22Hex_bending_0.005N",
"22Hex_bending_0.01N",
"22Hex_bending_0.03N",
"22Hex_bending_0.05N",
"22Hex_pullOppositeVerts_0.05N",
"22Hex_pullOppositeVerts_0.1N",
"22Hex_pullOppositeVerts_0.3N",
"22Hex_shear_2N",
"22Hex_shear_5N",
"22Hex_axial_10N",
"22Hex_axial_20N",
"22Hex_cylinder_0.05N",
"22Hex_cylinder_0.1N",
"22Hex_s_0.05N",
"22Hex_s_0.1N"};
std::unordered_map<size_t, size_t> shuffleToNumOfOccur;
public:
ReducedPatternSimulator(
const std::vector<ReducedPatternOptimization::Results> &optimizationResults);
void simulate(std::shared_ptr<VCGPolyMesh> &tileIntoSurface,
std::vector<ReducedPatternOptimization::Results> &optimizationResults,
PatternGeometry &reducedPattern);
/*
* centers the surface
* scales it such that its average base triangle size matches a desired one. This is done in order to match the base triangle on which the reduced pattern was optimized on
* */
void preprocessSurface(const double &desiredBaseTriangleHeight, VCGPolyMesh &surface);
static void applyOptimizationResults_elements(
const ReducedPatternOptimization::Results &reducedPattern_optimizationResults,
const std::shared_ptr<SimulationMesh> &pTiledReducedPattern_simulationMesh,
const std::vector<size_t> &elementIndices);
static void applyOptimizationResults_innerHexagon(
const ReducedPatternOptimization::Results &reducedPattern_optimizationResults,
const vcg::Triangle3<double> &patternBaseTriangle,
PatternGeometry &reducedPattern);
static std::vector<ReducedPatternOptimization::Results> loadOptimizationResults(
const std::filesystem::path &optimizationResultsFolderPath);
private:
std::shared_ptr<VCGPolyMesh> pTileIntoSurface;
std::vector<PatternGeometry> fullPatterns;
static void createSimulationJobs(const Vector6d &externalForce,
SimulationJob &job_fullPattern,
SimulationJob &job_reducedPattern);
void createGuiMenu();
std::pair<FullPatternVertexIndex, ReducedPatternVertexIndex> getPickedVertices(
const std::pair<std::string, size_t> &selection) const;
void reset();
void saveJobs(const filesystem::__cxx11::path &outputFolderPath);
void saveResults(const std::string &outputFolderPath,
SimulationResults &fullResults,
SimulationResults &reducedResults);
void createTiledSimulationMeshes(std::vector<PatternGeometry> &fullPatterns,
std::vector<PatternGeometry> &reducedPatterns);
using OptimizationResultsIndex = size_t;
void createTiledSimulationMeshes(
const std::shared_ptr<ConstVCGPolyMesh> &pTileIntoSurface,
std::vector<ReducedPatternOptimization::Results> &optimizationResults,
const std::vector<OptimizationResultsIndex> &perSurfaceFacePatternIndices);
void createTiledSimulationMeshes(
const std::shared_ptr<ConstVCGPolyMesh> &tileIntoSurface,
std::vector<ReducedPatternOptimization::Results> &optimizationResults,
const std::vector<OptimizationResultsIndex> &perSurfaceFacePatterns,
std::vector<size_t> &tileIntoEdgeToTiledFullPattern);
void loadScenario(const std::string &scenarioLabel);
std::pair<DRMFullSimulationResults, ReducedSimulationResults> runSimulations(
const std::string &scenarioLabel,
const bool &shouldRerunFullPatternSimulation = false,
const bool &showReducedPatternResultsBeforeRunningDRM = false);
void runShufflingEvaluation(
const std::vector<ReducedPatternOptimization::Results> &optimizationResults,
const std::vector<size_t> &tileIntoEiToTiledFullVi);
void shuffleReducedPatterns(
std::shared_ptr<SimulationMesh> &pSimulationMesh_tiledShuffledReduced,
std::unordered_map<VertexIndex, VertexIndex> &fullToShuffledReduced);
double computeDistance(
const SimulationResults &resultsA,
const SimulationResults &resultsB,
const std::unordered_map<VertexIndex, VertexIndex> &resultAToResultsBViMap) const;
std::vector<double> computeDistancesPerScenario(
const std::vector<std::string> &scenarioLabels = std::vector<std::string>(),
const bool &shouldRerunDRMSimulation = false,
const bool &shouldDraw = false);
double computeDistance(const std::string &scenarioLabel,
const bool &shouldRerunDRMSimulation,
const bool &shouldDraw);
void tileReducedPatterns(
const std::vector<ReducedPatternOptimization::Results> &optimizationResults,
const std::vector<size_t> &perSurfaceFacePatternIndices,
std::shared_ptr<SimulationMesh> &pSimulationMesh_tiledReduced,
std::vector<size_t> &tileIntoEdgeToTiledReduced);
void shuffleReducedPatterns(
const std::vector<ReducedPatternOptimization::Results> &optimizationResults,
const std::vector<size_t> &tileIntoEdgeToTiledFullPattern,
const std::vector<size_t> &perSurfaceFacePatternIndices);
void runWeightEvaluation(const std::filesystem::path &optimizationResultsFolderPath);
void constructViMaps(const std::vector<size_t> &tileIntoEdgeToTiledFullPattern,
const std::vector<size_t> &tileIntoEdgeToTiledReducedPattern);
std::vector<size_t> computePerSurfaceFacePatternsIndices(
const std::vector<ReducedPatternOptimization::Results> &optimizationResults) const;
void tileFullPatterns(std::vector<ConstPatternGeometry> &fullPatterns,
const std::vector<size_t> &perSurfaceFacePatternIndices,
std::shared_ptr<SimulationMesh> &pTiledFullPattern_simulationMesh,
std::vector<size_t> &tileIntoEdgeToTiledFullVi);
void fillFullPatterns(std::vector<ReducedPatternOptimization::Results> &optimizationResults);
void computeLabels(const std::vector<ReducedPatternOptimization::Results> &optimizationResults,
const std::vector<size_t> &perSurfaceFacePatternIndex);
void createShufflings(std::vector<ReducedPatternOptimization::Results> &optimizationResults);
void generateRandomSimulationScenario(const std::array<float, 4> &randomScenarioParameters);
std::tuple<DRMFullSimulationResults, ReducedSimulationResults, LinearFullSimulationResults>
runAllSimulations(const string &jobLabel,
const bool &shouldRerunDRMFullPatternSimulation = false,
const bool &showReducedPatternResultsBeforeDRM = true);
void reportDistances(const std::tuple<DRMFullSimulationResults,
ReducedSimulationResults,
LinearFullSimulationResults> &simulationResults,
const string &csvFilePath = {});
};
#endif // REDUCEDPATTERNSIMULATOR_HPP