--- /dev/null
+/*=========================================================================
+ Program: vv http://www.creatis.insa-lyon.fr/rio/vv
+
+ Authors belong to:
+ - University of LYON http://www.universite-lyon.fr/
+ - Léon Bérard cancer center http://www.centreleonberard.fr
+ - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the copyright notices for more information.
+
+ It is distributed under dual licence
+
+ - BSD See included LICENSE.txt file
+ - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+ ===========================================================================**/
+
+#ifndef CLITKRELATIVEPOSITIONANALYZERFILTER_H
+#define CLITKRELATIVEPOSITIONANALYZERFILTER_H
+
+// clitk
+#include "clitkFilterWithAnatomicalFeatureDatabaseManagement.h"
+#include "clitkFilterBase.h"
+#include "clitkRelativePositionDataBase.h"
+
+namespace clitk {
+
+ //--------------------------------------------------------------------
+ /*
+ Load a database of relative positions. Analyze it and provide
+ common relative position for each patient.
+ */
+ //--------------------------------------------------------------------
+
+ class RelativePositionDataBaseAnalyzerFilter:
+ public virtual clitk::FilterBase,
+ public clitk::FilterWithAnatomicalFeatureDatabaseManagement
+ {
+
+ public:
+ RelativePositionDataBaseAnalyzerFilter();
+ virtual ~RelativePositionDataBaseAnalyzerFilter() {}
+
+ // Input
+ itkGetConstMacro(DatabaseFilename, std::string);
+ itkSetMacro(DatabaseFilename, std::string);
+ itkGetConstMacro(StationName, std::string);
+ itkSetMacro(StationName, std::string);
+ itkGetConstMacro(ObjectName, std::string);
+ itkSetMacro(ObjectName, std::string);
+ itkGetConstMacro(OutputFilename, std::string);
+ itkSetMacro(OutputFilename, std::string);
+
+ // For debug
+ void PrintOptions();
+
+ // Go !
+ virtual void Update();
+
+ protected:
+ std::string m_DatabaseFilename;
+ std::string m_StationName;
+ std::string m_ObjectName;
+ std::string m_OutputFilename;
+ clitk::RelativePositionDataBase db;
+
+ bool ComputeOptimalThreshold(RelativePositionDataBaseIndexType & index, double & threshold);
+
+ }; // end class
+ //--------------------------------------------------------------------
+
+} // end namespace clitk
+//--------------------------------------------------------------------
+
+#include "clitkRelativePositionDataBaseAnalyzerFilter.txx"
+
+#endif
--- /dev/null
+/*=========================================================================
+ Program: vv http://www.creatis.insa-lyon.fr/rio/vv
+
+ Authors belong to:
+ - University of LYON http://www.universite-lyon.fr/
+ - Léon Bérard cancer center http://www.centreleonberard.fr
+ - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the copyright notices for more information.
+
+ It is distributed under dual licence
+
+ - BSD See included LICENSE.txt file
+ - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+ ===========================================================================**/
+
+//--------------------------------------------------------------------
+clitk::RelativePositionDataBaseAnalyzerFilter::
+RelativePositionDataBaseAnalyzerFilter():
+ clitk::FilterBase(),
+ clitk::FilterWithAnatomicalFeatureDatabaseManagement()
+{
+ VerboseFlagOff();
+ SetDatabaseFilename("default.dbrp");
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+void
+clitk::RelativePositionDataBaseAnalyzerFilter::
+PrintOptions()
+{
+ DD("TODO");
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+void
+clitk::RelativePositionDataBaseAnalyzerFilter::
+Update()
+{
+ // Load DB of relative position
+ db.Read(GetDatabaseFilename());
+
+ // Get list of objects, list of orientation
+ std::vector<std::string> m_ListOfObjects;
+ db.GetListOfObjects(GetStationName(), m_ListOfObjects);
+
+ // Set initial index in the DB
+ clitk::RelativePositionDataBase::IndexType index;
+ index.station = GetStationName();
+
+ // Loop over objects
+ std::vector<double> m_ListOfThresholds;
+ for(int i=0; i<m_ListOfObjects.size(); i++) {
+ // DD(i);
+ // DD(m_ListOfObjects[i]);
+ // Set current index
+ index.object = m_ListOfObjects[i];
+ // Get the list of orientation
+ std::vector<clitk::RelativePositionOrientationType> m_ListOfOrientations;
+ db.GetListOfOrientations(GetStationName(), index.object, m_ListOfOrientations);
+
+ // Loop over orientation
+ for(int j=0; j<m_ListOfOrientations.size(); j++) {
+ // DD(j);
+ // m_ListOfOrientations[j].Println();
+ // Set current index
+ index.orientation = m_ListOfOrientations[j];
+ // Compute the best RelPos parameters
+ double threshold;
+ bool ok = ComputeOptimalThreshold(index, threshold);
+ m_ListOfThresholds.push_back(threshold);
+
+ // Print debug FIXME
+ if (ok) {
+ std::cout << m_ListOfObjects[i] << " ";
+ m_ListOfOrientations[j].Print();
+ std::cout << " " << threshold << " " << ok << std::endl;
+ }
+ }
+ }
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+bool
+clitk::RelativePositionDataBaseAnalyzerFilter::
+ComputeOptimalThreshold(RelativePositionDataBaseIndexType & index, double & threshold)
+{
+ // Get list of patient
+ std::vector<std::string> & ListOfPatients = db.GetListOfPatients(index);
+ // DD(ListOfPatients.size());
+ // index.orientation.Println();
+
+ // For a given station, object, orientation
+ bool stop=false;
+ int i=0;
+ if (index.orientation.notFlag) threshold = 0.0;
+ else threshold = 1.0;
+ while (!stop && (i<ListOfPatients.size())) {
+ // DD(i);
+ index.patient = ListOfPatients[i];
+ // std::cout << i << " " << index.patient << " ";
+ // Check index
+ if (!db.CheckIndex(index)) {
+ std::cout << "Warning index does not exist in the DB. index = ";
+ index.Println(std::cout);
+ }
+ else {
+ // index = patient station object, orientation = angle1 angle2 notFlag
+ if (db.GetAreaGain(index) == 1.0) stop = true;
+ else {
+ if (index.orientation.notFlag) threshold = std::max(db.GetThreshold(index), threshold);
+ else threshold = std::min(db.GetThreshold(index), threshold);
+ // std::cout << db.GetThreshold(index) << " opt=" << threshold;
+ }
+ }
+ ++i;
+ }
+ // std::cout << std::endl;
+ // DD(threshold);
+ // DD(stop);
+ return !stop; // if stop before the end, this orientation is not useful.
+}
+//--------------------------------------------------------------------
--- /dev/null
+/*=========================================================================
+ Program: vv http://www.creatis.insa-lyon.fr/rio/vv
+
+ Authors belong to:
+ - University of LYON http://www.universite-lyon.fr/
+ - Léon Bérard cancer center http://www.centreleonberard.fr
+ - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the copyright notices for more information.
+
+ It is distributed under dual licence
+
+ - BSD See included LICENSE.txt file
+ - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+===========================================================================**/
+
+// clitk
+#include "clitkRelativePositionDataBaseAnalyzer_ggo.h"
+#include "clitkIO.h"
+#include "clitkRelativePositionDataBaseAnalyzerFilter.h"
+
+//--------------------------------------------------------------------
+int main(int argc, char * argv[]) {
+
+ // Init command line
+ GGO(clitkRelativePositionDataBaseAnalyzer, args_info);
+ CLITK_INIT;
+
+ // Filter
+ typedef clitk::RelativePositionDataBaseAnalyzerFilter FilterType;
+ FilterType filter;
+ filter.SetDatabaseFilename(args_info.db_arg);
+ filter.SetStationName(args_info.station_arg);
+ // filter.SetStationName(args_info.object_arg);//FIXME
+ filter.SetOutputFilename(args_info.output_arg);
+
+ try {
+ filter.Update();
+ } catch(std::runtime_error e) {
+ std::cout << e.what() << std::endl;
+ return EXIT_FAILURE;
+ }
+
+ return EXIT_SUCCESS;
+} // This is the end, my friend
+//--------------------------------------------------------------------
--- /dev/null
+#File clitkRelativePositionDataBaseAnalyzer.ggo
+package "clitkRelativePositionDataBaseAnalyzer"
+version "1.0"
+purpose "Analyze a DB of relative positions for several patient and structures"
+
+section "General options"
+option "config" - "Config file" string no
+option "verbose" v "Verbose" flag off
+
+section "Input/Output"
+option "db" i "Input database of RelPost" string yes
+option "station" s "Studied station name" string yes
+option "object" - "Studied object/struct name" string no
+option "output" o "Output rpl file" string yes