-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from BenceVirtonomy/merge_origin
Merge origin
- Loading branch information
Showing
63 changed files
with
3,885 additions
and
1,171 deletions.
There are no files selected for viewing
164 changes: 164 additions & 0 deletions
164
SPHINXsys/src/for_3D_build/geometries/complex_shape_image_mesh.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
#include "complex_shape_image_mesh.h" | ||
#include "image_mesh_shape.h" | ||
|
||
namespace SPH | ||
{ | ||
//=================================================================================================// | ||
bool ComplexShapeImageMesh::checkContain(const Vec3d& input_pnt, bool BOUNDARY_INCLUDED) | ||
{ | ||
bool exist = false; | ||
bool inside = false; | ||
|
||
for (auto& each_shape : image_mesh_shapes_) | ||
{ | ||
ImageMeshShape* sp = each_shape.first; | ||
ShapeBooleanOps operation_string = each_shape.second; | ||
|
||
switch (operation_string) | ||
{ | ||
case ShapeBooleanOps::add: | ||
{ | ||
inside = sp->checkContain(input_pnt); | ||
exist = exist || inside; | ||
break; | ||
} | ||
case ShapeBooleanOps::sub: | ||
{ | ||
inside = sp->checkContain(input_pnt); | ||
exist = exist && (!inside); | ||
break; | ||
} | ||
default: | ||
{ | ||
throw std::runtime_error("FAILURE: the boolean operation is not applicable!"); | ||
break; | ||
} | ||
} | ||
} | ||
return exist; | ||
} | ||
//=================================================================================================// | ||
Vec3d ComplexShapeImageMesh::findClosestPoint(const Vec3d& input_pnt) | ||
{ | ||
//a big positive number | ||
Real large_number(Infinity); | ||
Real dist_min = large_number; | ||
Vec3d pnt_closest(0); | ||
Vec3d pnt_found(0); | ||
|
||
for (auto& each_shape : image_mesh_shapes_) | ||
{ | ||
ImageMeshShape* sp = each_shape.first; | ||
pnt_found = sp->findClosestPoint(input_pnt); | ||
Real dist = (input_pnt - pnt_found).norm(); | ||
|
||
if(dist <= dist_min) | ||
{ | ||
dist_min = dist; | ||
pnt_closest = pnt_found; | ||
} | ||
} | ||
|
||
return pnt_closest; | ||
} | ||
//=================================================================================================// | ||
Real ComplexShapeImageMesh::findSignedDistance(const Vec3d& input_pnt) | ||
{ | ||
return image_mesh_shapes_[0].first->findValueAtPoint(input_pnt); | ||
} | ||
//=================================================================================================// | ||
Vec3d ComplexShapeImageMesh::findNormalDirection(const Vec3d& input_pnt) | ||
{ | ||
Vecd direction_to_surface = image_mesh_shapes_[0].first->findNormalAtPoint(input_pnt); | ||
bool is_contain = image_mesh_shapes_[0].first->checkContain(input_pnt); | ||
return is_contain ? direction_to_surface : -1.0 * direction_to_surface; | ||
} | ||
//=================================================================================================// | ||
void ComplexShapeImageMesh::addImageMeshShape(ImageMeshShape* image_mesh_shape, ShapeBooleanOps op) | ||
{ | ||
std::pair<ImageMeshShape*, ShapeBooleanOps> shape_and_op(image_mesh_shape, op); | ||
image_mesh_shapes_.push_back(shape_and_op); | ||
} | ||
//=================================================================================================// | ||
void ComplexShapeImageMesh::addBrick(Vec3d halfsize, int resolution, Vec3d translation, Mat3d rotation, ShapeBooleanOps op) | ||
{ | ||
std::cout << __FILE__ << ':' << __LINE__ << std::endl; | ||
throw std::runtime_error("addBrick is not implemented"); | ||
} | ||
//=================================================================================================// | ||
void ComplexShapeImageMesh::addSphere(Real radius, int resolution, Vec3d translation, Mat3d rotation, ShapeBooleanOps op) | ||
{ | ||
Vec3d spacings(resolution,resolution,resolution); | ||
Vec3d center(translation); | ||
ImageMeshShape* image_mesh_shape = new ImageMeshShape(radius, spacings, center); | ||
std::pair<ImageMeshShape*, ShapeBooleanOps> shape_and_op(image_mesh_shape, op); | ||
image_mesh_shapes_.push_back(shape_and_op); | ||
} | ||
//=================================================================================================// | ||
void ComplexShapeImageMesh::addCylinder(SimTK::UnitVec3 axis, Real radius, Real halflength, int resolution, Vec3d translation, Mat3d rotation, ShapeBooleanOps op) | ||
{ | ||
std::cout << __FILE__ << ':' << __LINE__ << std::endl; | ||
throw std::runtime_error("addCylinder is not implemented"); | ||
} | ||
//=================================================================================================// | ||
void ComplexShapeImageMesh::addComplexShapeImageMesh(ComplexShapeImageMesh* complex_shape_image_mesh, ShapeBooleanOps op) | ||
{ | ||
switch (op) | ||
{ | ||
case ShapeBooleanOps::add: | ||
{ | ||
for (auto& shape_and_op : complex_shape_image_mesh->image_mesh_shapes_) | ||
{ | ||
image_mesh_shapes_.push_back(shape_and_op); | ||
} | ||
break; | ||
} | ||
case ShapeBooleanOps::sub: | ||
{ | ||
for (auto& shape_and_op : complex_shape_image_mesh->image_mesh_shapes_) | ||
{ | ||
ImageMeshShape* sp = shape_and_op.first; | ||
ShapeBooleanOps operation_string | ||
= shape_and_op.second == ShapeBooleanOps::add ? ShapeBooleanOps::sub : ShapeBooleanOps::add; | ||
std::pair<ImageMeshShape*, ShapeBooleanOps> substract_shape_and_op(sp, operation_string); | ||
|
||
image_mesh_shapes_.push_back(substract_shape_and_op); | ||
} | ||
break; | ||
} | ||
default: | ||
{ | ||
throw std::runtime_error("unknown operation shape boolean operator"); | ||
break; | ||
} | ||
} | ||
} | ||
//=================================================================================================// | ||
bool ComplexShapeImageMesh::checkNotFar(const Vec3d& input_pnt, Real threshold) | ||
{ | ||
return checkContain(input_pnt) || checkNearSurface(input_pnt , threshold) ? true : false; | ||
} | ||
//=================================================================================================// | ||
bool ComplexShapeImageMesh::checkNearSurface(const Vec3d& input_pnt, Real threshold) | ||
{ | ||
return getMaxAbsoluteElement(input_pnt - findClosestPoint(input_pnt)) < threshold ? true : false; | ||
} | ||
//=================================================================================================// | ||
BoundingBox ComplexShapeImageMesh::findBounds() | ||
{ | ||
//initial reference values | ||
Vec3d lower_bound = Vec3d(Infinity); | ||
Vec3d upper_bound = Vec3d(-Infinity); | ||
|
||
for (size_t i = 0; i < image_mesh_shapes_.size(); i++) | ||
{ | ||
BoundingBox shape_bounds = image_mesh_shapes_[i].first->findBounds(); | ||
for (int j = 0; j != 3; ++j) { | ||
lower_bound[j] = SMIN(lower_bound[j], shape_bounds.first[j]); | ||
upper_bound[j] = SMAX(upper_bound[j], shape_bounds.second[j]); | ||
} | ||
} | ||
return BoundingBox(lower_bound, upper_bound); | ||
} | ||
//=================================================================================================// | ||
} |
90 changes: 90 additions & 0 deletions
90
SPHINXsys/src/for_3D_build/geometries/complex_shape_image_mesh.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* -------------------------------------------------------------------------* | ||
* SPHinXsys * | ||
* --------------------------------------------------------------------------* | ||
* SPHinXsys (pronunciation: s'finksis) is an acronym from Smoothed Particle * | ||
* Hydrodynamics for industrial compleX systems. It provides C++ APIs for * | ||
* physical accurate simulation and aims to model coupled industrial dynamic * | ||
* systems including fluid, solid, multi-body dynamics and beyond with SPH * | ||
* (smoothed particle hydrodynamics), a meshless computational method using * | ||
* particle discretization. * | ||
* * | ||
* SPHinXsys is partially funded by German Research Foundation * | ||
* (Deutsche Forschungsgemeinschaft) DFG HU1527/6-1, HU1527/10-1 * | ||
* and HU1527/12-1. * | ||
* * | ||
* Portions copyright (c) 2017-2020 Technical University of Munich and * | ||
* the authors' affiliations. * | ||
* * | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may * | ||
* not use this file except in compliance with the License. You may obtain a * | ||
* copy of the License at http://www.apache.org/licenses/LICENSE-2.0. * | ||
* * | ||
* --------------------------------------------------------------------------*/ | ||
/** | ||
* @file complex_shape_image_mesh.h | ||
* @brief x | ||
* @details x | ||
* x | ||
* @author Yijin Mao | ||
*/ | ||
|
||
#ifndef COMPLEX_SHAPE_IMAGE_MESH_H | ||
#define COMPLEX_SHAPE_IMAGE_MESH_H | ||
|
||
#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING | ||
|
||
#include "base_geometry.h" | ||
#include "SimTKcommon.h" | ||
#include "SimTKmath.h" | ||
#include "Simbody.h" | ||
#include "simbody_middle.h" | ||
#include "geometry.h" | ||
#include "complex_shape_mesh.h" | ||
//#include "image_mesh_shape.h" | ||
|
||
#include <iostream> | ||
#include <string> | ||
#include <fstream> | ||
|
||
/** Macro for APPLE compilers*/ | ||
#ifdef __APPLE__ | ||
#include <boost/filesystem.hpp> | ||
namespace fs = boost::filesystem; | ||
#else | ||
#include <experimental/filesystem> | ||
namespace fs = std::experimental::filesystem; | ||
#endif | ||
|
||
namespace SPH | ||
{ | ||
class ImageMeshShape; | ||
|
||
class ComplexShapeImageMesh : public ComplexShapeMesh | ||
{ | ||
public: | ||
ComplexShapeImageMesh() : ComplexShapeMesh("ComplexShapeImageMesh") {}; | ||
ComplexShapeImageMesh(std::string complex_shape_name) : ComplexShapeMesh(complex_shape_name) {}; | ||
virtual ~ComplexShapeImageMesh() {}; | ||
virtual BoundingBox findBounds() override; | ||
|
||
void addImageMeshShape(ImageMeshShape* image_mesh_shape, ShapeBooleanOps op); | ||
void addComplexShapeImageMesh(ComplexShapeImageMesh* complex_shape_image_mesh, ShapeBooleanOps op); | ||
virtual void addBrick(Vec3d halfsize, int resolution, Vec3d translation, Mat3d rotation, ShapeBooleanOps op); | ||
virtual void addSphere(Real radius, int resolution, Vec3d translation, Mat3d rotation, ShapeBooleanOps op); | ||
virtual void addCylinder(SimTK::UnitVec3 axis, Real radius, Real halflength, int resolution, Vec3d translation, Mat3d rotation, ShapeBooleanOps op); | ||
|
||
virtual bool checkContain(const Vec3d& input_pnt, bool BOUNDARY_INCLUDED = true); | ||
virtual bool checkNotFar(const Vec3d& input_pnt, Real threshold); | ||
virtual bool checkNearSurface(const Vec3d& input_pnt, Real threshold); | ||
/** Signed distance is negative for point within the complex shape. */ | ||
virtual Real findSignedDistance(const Vec3d& input_pnt); | ||
/** Normal direction point toward outside of the complex shape. */ | ||
virtual Vec3d findNormalDirection(const Vec3d& input_pnt); | ||
virtual Vec3d findClosestPoint(const Vec3d& input_pnt); | ||
protected: | ||
/** shape container<pointer to geomtry, operation> */ | ||
std::vector<std::pair<ImageMeshShape*, ShapeBooleanOps>> image_mesh_shapes_; | ||
}; | ||
} | ||
|
||
#endif //COMPLEX_SHAPE_IMAGE_MESH_H |
78 changes: 78 additions & 0 deletions
78
SPHINXsys/src/for_3D_build/geometries/complex_shape_mesh.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* -------------------------------------------------------------------------* | ||
* SPHinXsys * | ||
* --------------------------------------------------------------------------* | ||
* SPHinXsys (pronunciation: s'finksis) is an acronym from Smoothed Particle * | ||
* Hydrodynamics for industrial compleX systems. It provides C++ APIs for * | ||
* physical accurate simulation and aims to model coupled industrial dynamic * | ||
* systems including fluid, solid, multi-body dynamics and beyond with SPH * | ||
* (smoothed particle hydrodynamics), a meshless computational method using * | ||
* particle discretization. * | ||
* * | ||
* SPHinXsys is partially funded by German Research Foundation * | ||
* (Deutsche Forschungsgemeinschaft) DFG HU1527/6-1, HU1527/10-1 * | ||
* and HU1527/12-1. * | ||
* * | ||
* Portions copyright (c) 2017-2020 Technical University of Munich and * | ||
* the authors' affiliations. * | ||
* * | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may * | ||
* not use this file except in compliance with the License. You may obtain a * | ||
* copy of the License at http://www.apache.org/licenses/LICENSE-2.0. * | ||
* * | ||
* --------------------------------------------------------------------------*/ | ||
/** | ||
* @file complex_shape_mesh.h | ||
* @brief x. | ||
* @details x | ||
* x. | ||
* @author Yijin Mao | ||
*/ | ||
|
||
#ifndef COMPLEX_SHAPE_MESH_H | ||
#define COMPLEX_SHAPE_MESH_H | ||
|
||
#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING | ||
|
||
#include "SimTKcommon.h" | ||
#include "SimTKmath.h" | ||
|
||
#include <iostream> | ||
#include <string> | ||
#include <fstream> | ||
|
||
/** Macro for APPLE compilers*/ | ||
#ifdef __APPLE__ | ||
#include <boost/filesystem.hpp> | ||
namespace fs = boost::filesystem; | ||
#else | ||
#include <experimental/filesystem> | ||
namespace fs = std::experimental::filesystem; | ||
#endif | ||
|
||
namespace SPH | ||
{ | ||
class ComplexShapeMesh | ||
{ | ||
public: | ||
//constructor for load stl file from out side | ||
ComplexShapeMesh(std::string name) : name_(name) {}; | ||
virtual ~ComplexShapeMesh() {}; | ||
virtual BoundingBox findBounds() = 0; | ||
virtual bool checkContain(const Vec3d& input_pnt, bool BOUNDARY_INCLUDED = true) = 0; | ||
virtual bool checkNotFar(const Vec3d& input_pnt, Real threshold) = 0; | ||
virtual bool checkNearSurface(const Vec3d& input_pnt, Real threshold) = 0; | ||
/** Signed distance is negative for point within the complex shape. */ | ||
virtual Real findSignedDistance(const Vec3d& input_pnt) = 0; | ||
/** Normal direction point toward outside of the complex shape. */ | ||
virtual Vec3d findNormalDirection(const Vec3d& input_pnt) = 0; | ||
|
||
virtual Vec3d findClosestPoint(const Vec3d& input_pnt) = 0; | ||
|
||
std::string getName() { return name_; } | ||
|
||
protected: | ||
std::string name_; | ||
}; | ||
} | ||
|
||
#endif //COMPLEX_SHAPE_MESH_H |
Oops, something went wrong.