IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
PythonPlanIndexedColl.h
Go to the documentation of this file.
1 // PythonPlanIndexedColl.h:
3 // ------------------------
4 //
14 
15 #ifndef __PYIPSDKBASE_PYTHONPLANINDEXEDCOLL_H__
16 #define __PYIPSDKBASE_PYTHONPLANINDEXEDCOLL_H__
17 
18 #include <IPSDKBaseData/PlanIndex/PlanIndex.h>
20 #include <IPSDKBaseData/PlanIndex/BasePlanIndexedColl.h>
21 #include <IPSDKBaseData/DataItem/Node/BaseDataItemNode.h>
23 #include <Python/PyIPSDKBase/PythonDataItem.h>
25 #include <boost/python/dict.hpp>
26 #include <boost/python/tuple.hpp>
27 #include <boost/utility/enable_if.hpp>
28 #include <boost/type_traits/is_base_of.hpp>
29 #include <IPSDKMath/Constants.h>
30 
31 namespace ipsdk {
32 namespace python {
33 
36 
39 template <typename CollType>
40 typename boost::enable_if<boost::is_base_of<BaseDataItemNode, typename CollType::ValueType>, boost::python::dict>::type
41 toPyDict(const boost::shared_ptr<const CollType>& pPlanIndexedColl)
42 {
43  // parse all plan indexed data
44  boost::python::dict resDict;
45  typedef BasePlanIndexedColl::PlanIndexedConstColl BaseCollType;
46  const BaseCollType& baseColl = pPlanIndexedColl->getBaseColl();
47  typename BaseCollType::const_iterator iter = baseColl.begin();
48  while (iter != baseColl.end()) {
49 
50  // retrieve current informations
51  const PlanIndex& curPlanIndex = iter->first;
52  const ipUInt32& curZPlanIdx = curPlanIndex.getZPlanIdx();
53  const ipUInt32& curCPlanIdx = curPlanIndex.getCPlanIdx();
54  const ipUInt32& curTPlanIdx = curPlanIndex.getTPlanIdx();
55  const SerializationObjectConstPtr& pCurBaseObject = iter->second;
56  const DataItemNodeConstPtr& pCurObject = boost::static_pointer_cast<const BaseDataItemNode>(pCurBaseObject);
57 
58  // insert current data item into collection
59  resDict[boost::python::make_tuple(curZPlanIdx, curCPlanIdx, curTPlanIdx)] = toPyDict(pCurObject);
60 
61  ++iter;
62  }
63 
64  return resDict;
65 }
66 
68 template <typename CollType>
69 typename boost::enable_if<boost::is_base_of<BaseDataItemNode, typename CollType::ValueType>, bool>::type
70 equal(const boost::shared_ptr<const CollType>& pPlanIndexedColl1,
71  const boost::shared_ptr<const CollType>& pPlanIndexedColl2,
73 {
74  // check collections size
75  if (pPlanIndexedColl1->getNbPlans() != pPlanIndexedColl2->getNbPlans())
76  return false;
77 
78  // parse all plan indexed data
79  typedef BasePlanIndexedColl::PlanIndexedConstColl BaseCollType;
80  const BaseCollType& baseColl1 = pPlanIndexedColl1->getBaseColl();
81  const BaseCollType& baseColl2 = pPlanIndexedColl2->getBaseColl();
82  typename BaseCollType::const_iterator iter1 = baseColl1.begin();
83  typename BaseCollType::const_iterator iter2 = baseColl2.begin();
84  while (iter1 != baseColl1.end()) {
85 
86  // retrieve current informations
87  const PlanIndex& curPlanIndex1 = iter1->first;
88  const ipUInt32& curZPlanIdx1 = curPlanIndex1.getZPlanIdx();
89  const ipUInt32& curCPlanIdx1 = curPlanIndex1.getCPlanIdx();
90  const ipUInt32& curTPlanIdx1 = curPlanIndex1.getTPlanIdx();
91  const DataItemConstPtr& pCurObject1 = boost::static_pointer_cast<const BaseDataItemNode>(iter1->second);
92  const PlanIndex& curPlanIndex2 = iter2->first;
93  const ipUInt32& curZPlanIdx2 = curPlanIndex2.getZPlanIdx();
94  const ipUInt32& curCPlanIdx2 = curPlanIndex2.getCPlanIdx();
95  const ipUInt32& curTPlanIdx2 = curPlanIndex2.getTPlanIdx();
96  const DataItemConstPtr& pCurObject2 = boost::static_pointer_cast<const BaseDataItemNode>(iter2->second);
97 
98  // check plan indexes validity
99  if (curZPlanIdx1 != curZPlanIdx2)
100  return false;
101  if (curCPlanIdx1 != curCPlanIdx2)
102  return false;
103  if (curTPlanIdx1 != curTPlanIdx2)
104  return false;
105 
106  // check data items equality
107  if (equal(*pCurObject1, *pCurObject2, tolerance) == false)
108  return false;
109 
110  ++iter1;
111  ++iter2;
112  }
113 
114  return true;
115 }
116 
117 // function allowing to compare two plan indexed data item collections (with out tolerance)
118 template <typename CollType>
119 typename boost::enable_if<boost::is_base_of<BaseDataItemNode, typename CollType::ValueType>, bool>::type
120 equalWithoutTol(const boost::shared_ptr<const CollType>& pPlanIndexedColl1,
121  const boost::shared_ptr<const CollType>& pPlanIndexedColl2)
122 {
123  return equal(pPlanIndexedColl1, pPlanIndexedColl2, NumericLimits<ipReal64>::sqrt_epsilon());
124 }
125 
126 //template <typename T>
127 //bool isPlanIndexed(const T& param)
128 //{
129 // return false;
130 //}
131 //
132 //template<> bool
133 //isPlanIndexed<ipsdk::BasePlanIndexedColl>(const ipsdk::BasePlanIndexedColl& param)
134 //{
135 // return true;
136 //}
137 
138 
141 
142 } // end of namespace python
143 } // end of namespace ipsdk
144 
147 
148 //IPSDK_PYTHON_MODULE_WRAPPER_REGISTRATOR(PlanIndexedColl)
150 //boost::python::def("isPlanIndexed", ipsdk::python::isPlanIndexed<ipsdk::BasePlanIndexedColl>, "function allowing to check whether two data items are equal");
151 //}
152 
153 #endif // __PYIPSDKBASE_PYTHONPLANINDEXEDCOLL_H__
Main namespace for IPSDK library.
Definition: AlgorithmFunctionEfficiency.h:22
boost::shared_ptr< const BaseDataItemNode > DataItemNodeConstPtr
shared pointer to const DataItemNode
Definition: DataItemTypes.h:161
boost::shared_ptr< const BaseSerializationObject > SerializationObjectConstPtr
shared pointer to a const base serialization object
Definition: SerializationTypes.h:32
boost::enable_if< boost::is_base_of< BaseDataItemNode, typename CollType::ValueType >, boost::python::dict >::type toPyDict(const boost::shared_ptr< const CollType > &pPlanIndexedColl)
Definition: PythonPlanIndexedColl.h:41
boost::shared_ptr< const BaseDataItem > DataItemConstPtr
shared pointer to const DataItem
Definition: DataItemTypes.h:149
Macros allowing to handle ipsdk to python wrapping.
ipUInt64 getZPlanIdx() const
access to plan indexes associated to object
Definition: PlanIndex.h:108
double ipReal64
Base types definition.
Definition: BaseTypes.h:57
Definition: NumericLimits.h:27
Predefined constants for ipsdk math library.
Utility functions for data item management.
Predefined types for plan indexed collection management.
Base class for data item nodes.
Definition: BaseDataItemNode.h:29
ipUInt64 getCPlanIdx() const
access to plan indexes associated to object
Definition: PlanIndex.h:114
Class used to store image plan index.
Definition: PlanIndex.h:26
std::map< PlanIndex, SerializationObjectConstPtr > PlanIndexedConstColl
collection of plan indexed serializable object shared pointers
Definition: BasePlanIndexedColl.h:45
boost::enable_if< boost::is_base_of< BaseDataItemNode, typename CollType::ValueType >, bool >::type equal(const boost::shared_ptr< const CollType > &pPlanIndexedColl1, const boost::shared_ptr< const CollType > &pPlanIndexedColl2, const ipReal64 &tolerance=NumericLimits< ipReal64 >::sqrt_epsilon())
function allowing to compare two plan indexed data item collections
Definition: PythonPlanIndexedColl.h:70
ipUInt64 getTPlanIdx() const
access to plan indexes associated to object
Definition: PlanIndex.h:120
uint32_t ipUInt32
Base types definition.
Definition: BaseTypes.h:53