12 #ifndef mitkCLPolyToNrrd_cpp 13 #define mitkCLPolyToNrrd_cpp 21 #include <itkImageRegionIteratorWithIndex.h> 31 int main(
int argc,
char* argv[])
38 parser.
addArgument(
"output",
"o",
mitkCommandLineParser::File,
"Output file",
"Output files. Two files are create, a .nrrd image and a 3d-vtk.",
us::Any(),
false,
false,
false,
mitkCommandLineParser::Input);
41 parser.
setTitle(
"2D-Polydata to Nrrd Segmentation");
42 parser.
setDescription(
"Creates a Nrrd segmentation based on a 2d-vtk polydata.");
45 std::map<std::string, us::Any> parsedArgs = parser.
parseArguments(argc, argv);
47 if (parsedArgs.size()==0)
51 if ( parsedArgs.count(
"help") || parsedArgs.count(
"h"))
61 MaskImageType::Pointer
mask = MaskImageType::New();
64 double minX, minY, minZ;
65 double maxX, maxY, maxZ;
67 maxX = maxY = maxZ = std::numeric_limits<double>::lowest();
69 for (
auto iter = points->Begin(); iter != points->End(); ++iter)
71 minX = std::min<double>(minX, iter.Value().GetElement(0));
72 minY = std::min<double>(minY, iter.Value().GetElement(1));
73 minZ = std::min<double>(minZ, iter.Value().GetElement(2));
74 maxX = std::max<double>(maxX, iter.Value().GetElement(0));
75 maxY = std::max<double>(maxY, iter.Value().GetElement(1));
76 maxZ = std::max<double>(maxZ, iter.Value().GetElement(2));
78 MaskImageType::PointType point;
79 MaskImageType::IndexType iMin;
80 MaskImageType::IndexType iMax;
84 mask->TransformPhysicalPointToIndex(point, iMin);
88 mask->TransformPhysicalPointToIndex(point, iMax);
90 itk::ImageRegionIteratorWithIndex<MaskImageType> iter(mask, mask->GetLargestPossibleRegion());
91 while (!iter.IsAtEnd())
93 MaskImageType::IndexType index = iter.GetIndex();
94 if ((index[0] >= iMin[0]) && (index[1] >= iMin[1]) && (index[2] >= iMin[2]) &&
95 (index[0] <= iMax[0]) && (index[1] <= iMax[1]) && (index[2] <= iMax[2]))
109 std::string saveAs = parsedArgs[
"output"].ToString();
void setContributor(std::string contributor)
void addArgument(const std::string &longarg, const std::string &shortarg, Type type, const std::string &argLabel, const std::string &argHelp=std::string(), const us::Any &defaultValue=us::Any(), bool optional=true, bool ignoreRest=false, bool deprecated=false, mitkCommandLineParser::Channel channel=mitkCommandLineParser::Channel::None)
std::map< std::string, us::Any > parseArguments(const StringContainerType &arguments, bool *ok=nullptr)
itk::Image< unsigned short, 3 > MaskImageType
Data structure which stores a set of points. Superclass of mitk::Mesh.
void setCategory(std::string category)
mitk::Image::Pointer image
void setArgumentPrefix(const std::string &longPrefix, const std::string &shortPrefix)
void CastToMitkImage(const itk::SmartPointer< ItkOutputImageType > &itkimage, itk::SmartPointer< mitk::Image > &mitkoutputimage)
Cast an itk::Image (with a specific type) to an mitk::Image.
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
static void Save(const mitk::BaseData *data, const std::string &path, bool setPathProperty=false)
Save a mitk::BaseData instance.
mitk::Image::Pointer mask
itk::Image< double, 3 > FloatImageType
void setTitle(std::string title)
void setDescription(std::string description)
int main(int argc, char *argv[])
static DataStorage::SetOfObjects::Pointer Load(const std::string &path, DataStorage &storage, const ReaderOptionsFunctorBase *optionsCallback=nullptr)
Load a file into the given DataStorage.