Skip to content

Issue 329 dev classification imr #332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions blocking/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,10 @@ if(WITH_TEST)
add_subdirectory(tst)
endif(WITH_TEST)
#==============================================================================

#==============================================================================
# EXECUTABLES
#==============================================================================
add_executable(blocking src/blocking_exe.cpp)
target_link_libraries(blocking PRIVATE ${GMDS_LIB})
target_compile_features(blocking PUBLIC cxx_std_14)
133 changes: 133 additions & 0 deletions blocking/src/blocking_exe.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*----------------------------------------------------------------------------*/
#include <gmds/ig/Mesh.h>
#include <gmds/ig/MeshDoctor.h>
#include <gmds/io/IGMeshIOService.h>
#include <gmds/io/VTKReader.h>
#include <gmds/io/VTKWriter.h>
#include <gmds/cadfac/FACManager.h>
#include <gmds/blocking/Blocking.h>
#include <gmds/blocking/CurvedBlocking.h>
#include <gmds/blocking/CurvedBlockingClassifier.h>

#include "fstream"
/*----------------------------------------------------------------------------*/
using namespace gmds;
/*----------------------------------------------------------------------------*/
void set_up_geom_model(gmds::cad::FACManager* AGeomModel, const std::string AFileName)
{
gmds::Mesh vol_mesh(gmds::MeshModel(gmds::DIM3 | gmds::R | gmds::F | gmds::E | gmds::N | gmds::R2N | gmds::R2F | gmds::R2E | gmds::F2N | gmds::F2R | gmds::F2E
| gmds::E2F | gmds::E2N | gmds::N2E));
//std::string dir(TEST_SAMPLES_DIR);
//std::string vtk_file = dir +"/"+ AFileName;
std::string vtk_file = AFileName;
gmds::IGMeshIOService ioService(&vol_mesh);
gmds::VTKReader vtkReader(&ioService);
vtkReader.setCellOptions(gmds::N | gmds::R);
vtkReader.read(vtk_file);
gmds::MeshDoctor doc(&vol_mesh);
doc.buildFacesAndR2F();
doc.buildEdgesAndX2E();
doc.updateUpwardConnectivity();
AGeomModel->initFrom3DMesh(&vol_mesh);

}

int main(int argc, char* argv[])
{
std::cout << "============== CLASSIFICATION ================" << std::endl;

/*
* The folder with the shapes to test needs to be defined like that :
* DataFolder/
* ||
* \/
* -folderShape1 / folderShape1.vtk (the geometry file) folderShape1_blocking.vtk (the blocking file)
* -folderShape2 / folderShape2.vtk (the geometry file) folderShape2_blocking.vtk (the blocking file)
* ....
* -folderShapeX / folderShapeX.vtk (the geometry file) folderShapeX_blocking.vtk (the blocking file)
*
* The file on entry is just a list of the folder's name:
* folderShape1
* folderShape2
* ...
* folderShapeX
*/
if (argc != 2) {
std::cout << "Require one paramater : \n";
std::cout << " - [IN ] the file with the name of the folder to go, \n";
throw gmds::GMDSException("Wrong number of parameters");
}
auto file = std::string(argv[1]);
//We browse the file until the end
std::ifstream m_stream(file);
std::string line;
while(std::getline(m_stream,line)){

//==================================================================
// PARAMETERS PARSING
//==================================================================
std::string file_geom, file_mesh, file_out;

//The path of the data folder
std::string path_data_folder = "/home/bourmaudp/Documents/DATA/Easy_Shapes_Class/";
//Path of the current folder with the geometry and the blocking
std::string path_folder_shape = path_data_folder+line+"/";
//Geometry file
file_geom = path_folder_shape+line+".vtk";
//Blocking file
file_mesh = path_folder_shape+line+"_blocking.vtk";
//The path to save the classification and the name of the file
file_out = path_folder_shape+line+"_blocking_class_save.vtk";
std::cout << "Parameters " << std::endl;
std::cout << " - Geometry file: " << file_geom << std::endl;
std::cout << " - Mesh file : " << file_mesh << std::endl;
std::cout << " - Output file : " << file_out << std::endl;
std::cout << "=======================================" << std::endl;

//==================================================================
// GEOMETRY READING
//==================================================================
gmds::cad::FACManager geom_model;
set_up_geom_model(&geom_model,file_geom);

//==================================================================
// MESH READING
//==================================================================
std::cout<<"> Start mesh reading"<<std::endl;
//the used model is specified according to the class requirements.
Mesh m(gmds::MeshModel(gmds::DIM3|gmds::N|gmds::R|gmds::R2N));

IGMeshIOService ioService2(&m);
VTKReader vtkReader2(&ioService2);
vtkReader2.setCellOptions(N|R);
vtkReader2.read(file_mesh);
MeshDoctor doc2(&m);
doc2.updateUpwardConnectivity();

//==================================================================
// CREATE THE BLOCKING FROM THE MESH
//==================================================================
gmds::blocking::CurvedBlocking bl(&geom_model, false);
bl.init_from_mesh(m);


//==================================================================
// CLASSIFICATION BETWEEN THE BLOCKING AND THE GEOMETRY
//==================================================================
gmds::blocking::CurvedBlockingClassifier classifier(&bl);
classifier.clear_classification();
auto errors = classifier.classify();

//==================================================================
// SAVE CLASSIFICATION
//==================================================================
gmds::Mesh blockingMesh(gmds::MeshModel(gmds::DIM3|gmds::N|gmds::E|gmds::F|gmds::R|gmds::E2N|gmds::F2N|gmds::R2N));
bl.convert_to_mesh(blockingMesh);

gmds::IGMeshIOService ios(&blockingMesh);
gmds::VTKWriter vtk_writer(&ios);
vtk_writer.setCellOptions(gmds::N|gmds::R);
vtk_writer.setDataOptions(gmds::N|gmds::R);
vtk_writer.write(file_out);
}
}
3 changes: 2 additions & 1 deletion blocking/tst/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ add_executable(GMDS_BLOCKING_TEST
WriterDartsVTKTestSuite.h
main_test.cpp
ExecutionActionsTestSuite.h
)
ClassificationTestSuite.h
)
#==============================================================================

if(WITH_CGNS)
Expand Down
79 changes: 79 additions & 0 deletions blocking/tst/ClassificationTestSuite.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*----------------------------------------------------------------------------*/
#include <gtest/gtest.h>
/*----------------------------------------------------------------------------*/
#include <gmds/blocking/CurvedBlocking.h>
#include <gmds/blocking/CurvedBlockingClassifier.h>
#include <gmds/cadfac/FACManager.h>
#include <gmds/ig/MeshDoctor.h>
#include <gmds/io/IGMeshIOService.h>
#include <gmds/io/VTKReader.h>
#include <unit_test_config.h>
/*----------------------------------------------------------------------------*/
/**@brief setup function that initialize a geometric model using the faceted
* representation and an input vtk file name. The vtk file must contain a
* tetrahedral mesh
*
* @param AGeomModel geometric model we initialize
* @param AFileName vtk filename
*/
void set_up_geom_model(gmds::cad::FACManager* AGeomModel, const std::string AFileName)
{
gmds::Mesh vol_mesh(gmds::MeshModel(gmds::DIM3 | gmds::R | gmds::F | gmds::E | gmds::N | gmds::R2N | gmds::R2F | gmds::R2E | gmds::F2N | gmds::F2R | gmds::F2E
| gmds::E2F | gmds::E2N | gmds::N2E));
std::string vtk_file = AFileName;
gmds::IGMeshIOService ioService(&vol_mesh);
gmds::VTKReader vtkReader(&ioService);
vtkReader.setCellOptions(gmds::N | gmds::R);
vtkReader.read(vtk_file);
gmds::MeshDoctor doc(&vol_mesh);
doc.buildFacesAndR2F();
doc.buildEdgesAndX2E();
doc.updateUpwardConnectivity();
AGeomModel->initFrom3DMesh(&vol_mesh);

}


TEST(ClassificationTestSuite, test_chord_collapse)
{
gmds::cad::FACManager geom_model;
set_up_geom_model(&geom_model,"tet_in_box.vtk");
gmds::blocking::CurvedBlocking bl(&geom_model, false);

gmds::Mesh m(gmds::MeshModel(gmds::DIM3|gmds::N|gmds::R|gmds::R2N));

gmds::GridBuilder gb(&m,3);
gb.execute(4,1.0, 4, 1.0, 4, 1.0);
bl.init_from_mesh(m);


std::vector<gmds::blocking::CurvedBlocking::Face> bl_faces = bl.get_all_faces();

ASSERT_EQ(bl.get_nb_cells<3>(),27);

bool found_face = false;
auto face_id = -1;
gmds::math::Point seed(1.5,1.5,0.0);
for(auto i=0; i<bl_faces.size() && !found_face;i++){
gmds::blocking::CurvedBlocking::Face fi = bl_faces[i];
gmds::math::Point ci = bl.get_center_of_face(fi);
if(ci.distance2(seed)<0.1){
found_face = true;
face_id=i;
}
}

std::vector<gmds::blocking::CurvedBlocking::Node> f_nodes = bl.get_nodes_of_face(bl_faces[face_id]);
bl.collapse_chord(bl_faces[face_id],f_nodes[0],f_nodes[2]);

ASSERT_EQ(bl.get_nb_cells<3>(),24);

gmds::Mesh m_out(gmds::MeshModel(gmds::DIM3 | gmds::N | gmds::E | gmds::F | gmds::R | gmds::E2N | gmds::F2N | gmds::R2N));
bl.convert_to_mesh(m_out);

gmds::IGMeshIOService ioService(&m_out);
gmds::VTKWriter writer(&ioService);
writer.setCellOptions(gmds::N | gmds::F);
writer.setDataOptions(gmds::N |gmds::F );
writer.write("collapse.vtk");
}
Loading