-
Notifications
You must be signed in to change notification settings - Fork 34
Feature to convert a tracks file to a density map #114
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
Merged
Florent2305
merged 9 commits into
Inria-Empenn:master
from
Gregoire-V:ShapeToDensityFeature
Jan 20, 2025
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f37a285
add of a feature to convert a tracks file to a density map
5d474be
Improve the main algorithm and comment the code
86273fa
Update animaShapesToDensity.cxx
Florent2305 1740184
Correction of an error in the main algorithm part
8cb68d0
Fix syntax typos
Gregoire-V 6f16368
Merge remote-tracking branch 'origin/master' into ShapeToDensityFeature
Gregoire-V 53f7495
Merge actual animaFibersCounter.cxx and animaShapesToDensity.cxx insi…
Gregoire-V f9fbc36
Removal of a forgotten std::cout
Gregoire-V 3b5e3f4
Rename animaFibersCounter_fusion.cxx and add of a reminder about orie…
Gregoire-V File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
38 changes: 38 additions & 0 deletions
38
Anima/math-tools/common_tools/shapes_to_density/CMakeLists.txt
This file contains hidden or 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,38 @@ | ||
| if(BUILD_TOOLS) | ||
|
|
||
| project(animaShapesToDensity) | ||
|
|
||
| ## ############################################################################# | ||
| ## List Sources | ||
| ## ############################################################################# | ||
|
|
||
| list_source_files(${PROJECT_NAME} | ||
| ${CMAKE_CURRENT_SOURCE_DIR} | ||
| ) | ||
|
|
||
| ## ############################################################################# | ||
| ## add executable | ||
| ## ############################################################################# | ||
|
|
||
| add_executable(${PROJECT_NAME} | ||
| ${${PROJECT_NAME}_CFILES} | ||
| ) | ||
|
|
||
|
|
||
| ## ############################################################################# | ||
| ## Link | ||
| ## ############################################################################# | ||
|
|
||
| target_link_libraries(${PROJECT_NAME} | ||
| ${VTK_LIBRARIES} | ||
| ${ITKIO_LIBRARIES} | ||
| AnimaDataIO | ||
| ) | ||
|
|
||
| ## ############################################################################# | ||
| ## install | ||
| ## ############################################################################# | ||
|
|
||
| set_exe_install_rules(${PROJECT_NAME}) | ||
|
|
||
| endif() |
111 changes: 111 additions & 0 deletions
111
Anima/math-tools/common_tools/shapes_to_density/animaShapesToDensity.cxx
Florent2305 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
This file contains hidden or 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,111 @@ | ||
| #include <animaShapesReader.h> | ||
| #include <animaReadWriteFunctions.h> | ||
| #include <itkVectorImage.h> | ||
| #include <itkImageIOFactory.h> | ||
|
|
||
| #include <vtkVector.h> | ||
|
|
||
| #include <tclap/CmdLine.h> | ||
| #include <fstream> | ||
|
|
||
Florent2305 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| template <typename T> int sgn(T val) { | ||
| return (T(0) < val) - (val < T(0)); | ||
| } | ||
|
|
||
| int main(int argc, char **argv) | ||
| { | ||
| TCLAP::CmdLine cmd("INRIA / IRISA - VisAGeS/Empenn Team", ' ', ANIMA_VERSION); | ||
|
|
||
| TCLAP::ValueArg <std::string> inTrackArg("i","in-tracks","input track file (vtp, vtk)",true,"","input tracks",cmd); | ||
| TCLAP::ValueArg <std::string> geometryArg("g","geometry","Output image geometry",true,"","output geometry",cmd); | ||
| TCLAP::ValueArg <std::string> outArg("o","out","Output image representing fibers convert in binary image",true,"","output image",cmd); | ||
|
|
||
| try | ||
| { | ||
| cmd.parse(argc,argv); | ||
| } | ||
| catch (TCLAP::ArgException& e) | ||
| { | ||
| std::cerr << "Error: " << e.error() << "for argument " << e.argId() << std::endl; | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
| typedef itk::Image <double,3> ImageType; | ||
|
|
||
| ImageType::Pointer geomImage = anima::readImage <ImageType> (geometryArg.getValue()); | ||
|
|
||
| using OutImageType = itk::Image <double, 3>; | ||
|
|
||
| // OutImageType::DirectionType direction; | ||
Gregoire-V marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // direction.SetIdentity(); | ||
| // OutImageType::RegionType region; | ||
| OutImageType::Pointer outImage = OutImageType::New(); | ||
|
|
||
| outImage->Initialize(); | ||
| outImage->SetRegions(geomImage->GetLargestPossibleRegion()); | ||
| outImage->SetSpacing(geomImage->GetSpacing()); | ||
| outImage->SetOrigin(geomImage->GetOrigin()); | ||
| outImage->SetDirection(geomImage->GetDirection()); | ||
|
|
||
| outImage->Allocate(); | ||
| outImage->FillBuffer(0); | ||
|
|
||
| anima::ShapesReader trackReader; | ||
| trackReader.SetFileName(inTrackArg.getValue()); | ||
| trackReader.Update(); | ||
|
|
||
| vtkSmartPointer<vtkPolyData> tracks = trackReader.GetOutput(); | ||
|
|
||
| vtkIdType nbCells = tracks->GetNumberOfCells(); | ||
|
|
||
| double ptVals[3], ptValsNext[3], ptValsTmp[3]; | ||
| OutImageType::IndexType index; | ||
| OutImageType::PointType point; | ||
|
|
||
| for (int j = 0;j < nbCells;++j) | ||
| { | ||
| vtkCell *cell = tracks->GetCell(j); | ||
| vtkPoints *cellPts = cell->GetPoints(); | ||
| vtkIdType nbPts = cellPts->GetNumberOfPoints(); | ||
|
|
||
| for (int i = 0;i < nbPts-1 ;++i) | ||
| { | ||
| cellPts->GetPoint(i,ptVals); | ||
| cellPts->GetPoint(i+1,ptValsNext); | ||
|
|
||
| if(i == 0) | ||
| { | ||
| for (unsigned int k = 0;k < 3;++k) | ||
| point[k] = ptVals[k]; | ||
|
|
||
| outImage->TransformPhysicalPointToIndex(point,index); | ||
| outImage->SetPixel(index, 1); | ||
| } | ||
|
|
||
| double dist = 2; | ||
Florent2305 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| double dx, dy, dz; | ||
| while(dist >= 1.5) | ||
Florent2305 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| dx = ptValsNext[0] - ptVals[0]; | ||
| dy = ptValsNext[1] - ptVals[1]; | ||
| dz = ptValsNext[2] - ptVals[2]; | ||
|
|
||
| dist = std::sqrt(dx*dx + dy*dy + dz*dz); | ||
|
|
||
| ptVals[0] = ptVals[0] + sgn(dx); | ||
| ptVals[1] = ptVals[1] + sgn(dy); | ||
| ptVals[2] = ptVals[2] + sgn(dz); | ||
|
|
||
| for (unsigned int k = 0;k < 3;++k) | ||
| point[k] = ptVals[k]; | ||
|
|
||
| outImage->TransformPhysicalPointToIndex(point,index); | ||
| outImage->SetPixel(index, outImage->GetPixel(index) + 1.0); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| anima::writeImage <OutImageType> (outArg.getValue(), outImage); | ||
|
|
||
| return EXIT_SUCCESS; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.