Skip to content

Commit

Permalink
Added DiskMesh example. Improved Serialize example.
Browse files Browse the repository at this point in the history
  • Loading branch information
XaverKlemenschits committed Mar 4, 2021
1 parent f32a9ee commit 1e9953f
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 8 deletions.
10 changes: 10 additions & 0 deletions Tests/DiskMesh/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.4)

project("DiskMesh")

find_package(ViennaHRLE REQUIRED)
find_package(ViennaLS REQUIRED)

add_executable(${PROJECT_NAME} ${PROJECT_NAME}.cpp)
target_include_directories(${PROJECT_NAME} PUBLIC ${VIENNALS_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} PRIVATE ${VIENNALS_LIBRARIES})
67 changes: 67 additions & 0 deletions Tests/DiskMesh/DiskMesh.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include <chrono>
#include <iostream>

#include <lsBooleanOperation.hpp>
#include <lsDomain.hpp>
#include <lsExpand.hpp>
#include <lsFromSurfaceMesh.hpp>
#include <lsMakeGeometry.hpp>
#include <lsToSurfaceMesh.hpp>
#include <lsToDiskMesh.hpp>
#include <lsVTKWriter.hpp>

/**
Minimal example showing how to write different
meshes created by the algorithms lsToVoxelMesh and lsToSurfaceMesh.
\example Make3DSphere.cpp
*/

int main() {

constexpr int D = 3;

omp_set_num_threads(1);

double gridDelta = 0.4;

auto sphere1 =
lsSmartPointer<lsDomain<double, D>>::New(gridDelta); //, boundaryCons);

auto sphere2 =
lsSmartPointer<lsDomain<double, D>>::New(gridDelta); //, boundaryCons);
double origin[3] = {5., 0., 0.};
double radius = 7.3;

lsMakeGeometry<double, D>(
sphere1, lsSmartPointer<lsSphere<double, D>>::New(origin, radius))
.apply();
origin[0] = -5.;
lsMakeGeometry<double, D>(
sphere2, lsSmartPointer<lsSphere<double, D>>::New(origin, radius))
.apply();

std::cout << "Number of points: " << sphere1->getDomain().getNumberOfPoints()
<< std::endl;
auto mesh = lsSmartPointer<lsMesh>::New();

std::cout << "Expanding..." << std::endl;
lsExpand<double, D>(sphere1, 2).apply();
lsExpand<double, D>(sphere2, 2).apply();

std::cout << "Booling..." << std::endl;
lsBooleanOperation<double, D>(sphere1, sphere2, lsBooleanOperationEnum::UNION)
.apply();

std::cout << "Extracting..." << std::endl;
lsToDiskMesh<double, D>(sphere1, mesh).apply();
std::cout << "Disk mesh:" << std::endl;
mesh->print();
lsVTKWriter(mesh, "disks-" + std::to_string(radius) + ".vtk").apply();

lsToSurfaceMesh<double, D>(sphere1, mesh).apply();
std::cout << "Surface mesh:" << std::endl;
mesh->print();
lsVTKWriter(mesh, "surface-" + std::to_string(radius) + ".vtk").apply();

return 0;
}
29 changes: 21 additions & 8 deletions Tests/Serialize/Serialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
#include <lsDomain.hpp>
#include <lsMakeGeometry.hpp>
#include <lsPointData.hpp>
#include <lsToSurfaceMesh.hpp>
#include <lsToMesh.hpp>
#include <lsVTKWriter.hpp>
#include <lsReader.hpp>
#include <lsWriter.hpp>

/**
Minimal example showing how to serialize an lsDomain and deserialize.
Expand Down Expand Up @@ -37,16 +42,18 @@ int main() {
data.insertNextScalarData(scalars, "myScalars");
data.insertNextVectorData(vectors, "myVectors");

{
std::ofstream fout("test.lvst", std::ofstream::binary);
levelSet->serialize(fout);
fout.close();
}
// {
// std::ofstream fout("test.lvst", std::ofstream::binary);
// levelSet->serialize(fout);
// fout.close();
// }
lsWriter<double, D>(levelSet, "test.lvst").apply();

{
auto newLevelSet = lsSmartPointer<lsDomain<double, D>>::New();
std::ifstream fin("test.lvst", std::ofstream::binary);
newLevelSet->deserialize(fin);
// std::ifstream fin("test.lvst", std::ofstream::binary);
lsReader<double, D>(newLevelSet, "test.lvst").apply();
// newLevelSet->deserialize(fin);
lsPointData &newData = newLevelSet->getPointData();
std::cout << newData.getScalarDataSize() << std::endl;
auto newScalars = newData.getScalarData(0);
Expand All @@ -59,8 +66,14 @@ int main() {
for (auto i : *newVectors) {
std::cout << i[0] << ", " << i[1] << ", " << i[2] << std::endl;
}
fin.close();
// fin.close();

auto mesh = lsSmartPointer<lsMesh>::New();
lsToMesh<double, D>(newLevelSet, mesh).apply();
lsVTKWriter(mesh, "test.vtk").apply();
}



return 0;
}

0 comments on commit 1e9953f

Please sign in to comment.