Operations3D.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539
  1. /**
  2. * @file Operation3D.h
  3. * @brief abstract class for any kind of feature extraction from 3d images
  4. * @author Björn Fröhlich, Sven Sickert
  5. * @date 24.04.2012
  6. */
  7. #include <core/image/MultiChannelImageT.h>
  8. #include <core/image/MultiChannelImage3DT.h>
  9. #define BOUND(x,min,max) (((x)<(min))?(min):((x)>(max)?(max):(x)))
  10. namespace OBJREC {
  11. class Operation3D;
  12. /**
  13. * @brief methods for value access
  14. **/
  15. enum ValueTypes
  16. {
  17. RAWFEAT,
  18. CONTEXT
  19. };
  20. /**
  21. * @brief feature extraction methods
  22. **/
  23. enum OperationTypes {
  24. MINUS,
  25. MINUSABS,
  26. ADDITION,
  27. ONLY1,
  28. INTEGRAL,
  29. INTEGRALCENT,
  30. BIINTEGRALCENT,
  31. HAARHORIZ,
  32. HAARVERT,
  33. HAARSTACK,
  34. HAARDIAGXY,
  35. HAARDIAGXZ,
  36. HAARDIAGYZ,
  37. HAAR3HORIZ,
  38. HAAR3VERT,
  39. HAAR3STACK,
  40. RELATIVEXPOSITION,
  41. RELATIVEYPOSITION,
  42. RELATIVEZPOSITION,
  43. GLOBALFEATS,
  44. EQUALITY,
  45. RAYDIFF,
  46. RAYDIST,
  47. RAYORIENT,
  48. RAYNORM,
  49. MINUS_C,
  50. MINUSABS_C,
  51. ADDITION_C,
  52. ONLY1_C,
  53. INTEGRAL_C,
  54. INTEGRALCENT_C,
  55. BIINTEGRALCENT_C,
  56. HAARHORIZ_C,
  57. HAARVERT_C,
  58. HAARSTACK_C,
  59. HAARDIAGXY_C,
  60. HAARDIAGXZ_C,
  61. HAARDIAGYZ_C,
  62. HAAR3HORIZ_C,
  63. HAAR3VERT_C,
  64. HAAR3STACK_C,
  65. GLOBALFEATS_C,
  66. BIINTEGRAL,
  67. BIINTEGRAL_C,
  68. NBOPERATIONS
  69. };
  70. /**
  71. * @brief node class for context tree
  72. **/
  73. class TreeNode
  74. {
  75. public:
  76. /** left child node */
  77. int left;
  78. /** right child node */
  79. int right;
  80. /** position of feat for decision */
  81. Operation3D *feat;
  82. /** decision stamp */
  83. double decision;
  84. /** is the node a leaf or not */
  85. bool isleaf;
  86. /** distribution in current node */
  87. std::vector<double> dist;
  88. /** depth of the node in the tree */
  89. int depth;
  90. /** how many pixels are in this node */
  91. int featcounter;
  92. /** unique number */
  93. int nodeNumber;
  94. /** simple constructor */
  95. TreeNode() : left ( -1 ), right ( -1 ), feat ( NULL ), decision ( -1.0 ), isleaf ( false ) {}
  96. /** standard constructor */
  97. TreeNode ( int _left, int _right, Operation3D *_feat, double _decision ) : left ( _left ), right ( _right ), feat ( _feat ), decision ( _decision ), isleaf ( false ) {}
  98. /**
  99. * @brief initialize node
  100. * @param _depth current depth in tree
  101. * @param _numClasses amount of classes (initialize distribution)
  102. * @param _nodeNumber unique node number
  103. */
  104. void init( int _depth, int _numClasses, int _nodeNumber)
  105. {
  106. depth = _depth;
  107. featcounter = 0;
  108. dist = std::vector<double> (_numClasses, 0.0);
  109. nodeNumber = _nodeNumber;
  110. }
  111. };
  112. /**
  113. * @brief holds all necessary information for feature extraction of 3d images
  114. **/
  115. struct Features {
  116. /** simple features like RGB values */
  117. NICE::MultiChannelImage3DT<double> *feats;
  118. /** probabilities for each region */
  119. std::vector<std::vector<double> > *rProbs;
  120. };
  121. /**
  122. * @brief abstract operation class
  123. **/
  124. class Operation3D
  125. {
  126. protected:
  127. /** two different points (e.g. for an rectangle or two positions), channels and size */
  128. int x1, y1, z1, x2, y2, z2, channel1, channel2, wsize;
  129. /** type of feature */
  130. int featType;
  131. /** context multiplier */
  132. unsigned short cMultiplier;
  133. bool init;
  134. bool context;
  135. public:
  136. /** simple constructor */
  137. Operation3D();
  138. /**
  139. * @brief set all parameters
  140. * @param _x1 position 1
  141. * @param _y1 position 1
  142. * @param _z1 position 1
  143. * @param _x2 position 2
  144. * @param _y2 position 2
  145. * @param _z2 position 2
  146. * @param _channel1 channel 1
  147. * @param _channel2 channel 2
  148. * @param _ftype feature type
  149. * @return void nothing
  150. **/
  151. virtual void set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, int _channel1, int _channel2, int _featType );
  152. /**
  153. * @brief set whether it is a context feature or not
  154. * @param _context context boolean
  155. * @return void nothing
  156. **/
  157. void setContext ( bool _context );
  158. /**
  159. * @brief return context information (set by setContext(bool)
  160. *
  161. * @return bool whether context is used or not
  162. **/
  163. bool getContext();
  164. /**
  165. * @brief set size of feature window
  166. * @param _wsize window size
  167. * @return void nothing
  168. **/
  169. void setWSize ( int _wsize );
  170. /**
  171. * @brief return context information (set by setContext(bool)
  172. *
  173. * @return int get feature type
  174. **/
  175. int getFeatType();
  176. /**
  177. * @brief abstract interface for feature computation
  178. * @param feats features
  179. * @param x current x position
  180. * @param y current y position
  181. * @param z current z position
  182. * @return double distance
  183. **/
  184. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z ) = 0;
  185. /**
  186. * @brief virtual clone operation instead of copy constructor (copy constructor does not work)
  187. **/
  188. virtual Operation3D* clone() = 0;
  189. /**
  190. * @brief print some infos about operation extraction type
  191. * @return string feature type
  192. **/
  193. virtual std::string writeInfos();
  194. /**
  195. * @brief exctract current image boarders
  196. * @param feats image information
  197. * @param xsize width
  198. * @param ysize height
  199. * @param zsize depth
  200. * @return void
  201. **/
  202. inline void getXYZ ( const Features &feats, int &xsize, int &ysize, int &zsize );
  203. /**
  204. * @brief extracts RAW-Type value from INTEGRAL-Type channel
  205. * @param feats image information
  206. * @param posX x-position
  207. * @param posY y-position
  208. * @param posZ z-position
  209. * @return double the original RAW-value at the coordinates
  210. **/
  211. inline double intToRaw ( const Features &feats, const int &posX, const int &posY, const int &posZ, int &channel );
  212. /**
  213. * @brief return operation type (for store and restore)
  214. * @return OperationTypes
  215. **/
  216. virtual OperationTypes getOps() = 0;
  217. /**
  218. * @brief store all information for current operation in stream
  219. * @param os out stream
  220. * @return void
  221. **/
  222. virtual void store ( std::ostream & os );
  223. /**
  224. * @brief restore all information for current operation from stream
  225. * @param is in stream
  226. * @return void
  227. **/
  228. virtual void restore ( std::istream & is );
  229. };
  230. /**
  231. * @brief simple equality check ?(A==B)
  232. **/
  233. class RegionFeat3D: public Operation3D
  234. {
  235. public:
  236. /**
  237. * @brief interface for feature computation
  238. * @param feats features
  239. * @param x current x position
  240. * @param y current y position
  241. * @param z current z position
  242. * @return double distance
  243. **/
  244. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  245. /**
  246. * @brief clone operation instead of copy constructor (copy constructor does not work)
  247. **/
  248. virtual Operation3D* clone()
  249. {
  250. Operation3D* o = new RegionFeat3D();
  251. o->setContext(context);
  252. return o;
  253. }
  254. /**
  255. * @brief print some infos about operation extraction type
  256. * @return string feature type
  257. **/
  258. virtual std::string writeInfos()
  259. {
  260. return "(-)RegionFeat " + Operation3D::writeInfos();
  261. }
  262. /**
  263. * @brief return operation type (for store and restore)
  264. * @return OperationTypes
  265. **/
  266. virtual OperationTypes getOps()
  267. {
  268. return EQUALITY;
  269. }
  270. };
  271. /**
  272. * @brief simple difference operation A-B
  273. **/
  274. class Minus3D: public Operation3D
  275. {
  276. public:
  277. /**
  278. * @brief interface for feature computation
  279. * @param feats features
  280. * @param x current x position
  281. * @param y current y position
  282. * @param z current z position
  283. * @return double distance
  284. **/
  285. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  286. /**
  287. * @brief clone operation instead of copy constructor (copy constructor does not work)
  288. **/
  289. virtual Operation3D* clone()
  290. {
  291. Operation3D* o = new Minus3D();
  292. o->setContext(context);
  293. return o;
  294. }
  295. /**
  296. * @brief print some infos about operation extraction type
  297. * @return string feature type
  298. **/
  299. virtual std::string writeInfos()
  300. {
  301. std::string out = "Minus";
  302. if ( context )
  303. out = "(C)" + out;
  304. else
  305. out = "(R)" + out;
  306. return out + " " +Operation3D::writeInfos();
  307. }
  308. /**
  309. * @brief return operation type (for store and restore)
  310. * @return OperationTypes
  311. **/
  312. virtual OperationTypes getOps()
  313. {
  314. if (context)
  315. return MINUS_C;
  316. else
  317. return MINUS;
  318. }
  319. };
  320. /**
  321. * @brief simple absolute difference operation |A-B|
  322. **/
  323. class MinusAbs3D: public Operation3D
  324. {
  325. public:
  326. /**
  327. * @brief interface for feature computation
  328. * @param feats features
  329. * @param x current x position
  330. * @param y current y position
  331. * @param z current z position
  332. * @return double distance
  333. **/
  334. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  335. /**
  336. * @brief clone operation instead of copy constructor (copy constructor does not work)
  337. **/
  338. virtual Operation3D* clone()
  339. {
  340. Operation3D* o = new MinusAbs3D();
  341. o->setContext(context);
  342. return o;
  343. }
  344. /**
  345. * @brief print some infos about operation extraction type
  346. * @return string feature type
  347. **/
  348. virtual std::string writeInfos()
  349. {
  350. std::string out = "MinusAbs";
  351. if ( context )
  352. out = "(C)" + out;
  353. else
  354. out = "(R)" + out;
  355. return out + " " + Operation3D::writeInfos();
  356. }
  357. /**
  358. * @brief return operation type (for store and restore)
  359. * @return OperationTypes
  360. **/
  361. virtual OperationTypes getOps()
  362. {
  363. if (context)
  364. return MINUSABS_C;
  365. else
  366. return MINUSABS;
  367. }
  368. };
  369. /**
  370. * @brief simple addition operation A+B
  371. **/
  372. class Addition3D: public Operation3D
  373. {
  374. public:
  375. /**
  376. * @brief interface for feature computation
  377. * @param feats features
  378. * @param x current x position
  379. * @param y current y position
  380. * @param z current z position
  381. * @return double distance
  382. **/
  383. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  384. /**
  385. * @brief clone operation instead of copy constructor (copy constructor does not work)
  386. **/
  387. virtual Operation3D* clone()
  388. {
  389. Operation3D* o = new Addition3D();
  390. o->setContext(context);
  391. return o;
  392. }
  393. /**
  394. * @brief print some infos about operation extraction type
  395. * @return string feature type
  396. **/
  397. virtual std::string writeInfos()
  398. {
  399. std::string out = "Addition";
  400. if ( context )
  401. out = "(C)" + out;
  402. else
  403. out = "(R)" + out;
  404. return out + " " + Operation3D::writeInfos();
  405. }
  406. /**
  407. * @brief return operation type (for store and restore)
  408. * @return OperationTypes
  409. **/
  410. virtual OperationTypes getOps()
  411. {
  412. if (context)
  413. return ADDITION_C;
  414. else
  415. return ADDITION;
  416. }
  417. };
  418. /**
  419. * @brief simple single element access operation
  420. **/
  421. class Only13D: public Operation3D
  422. {
  423. public:
  424. /**
  425. * @brief interface for feature computation
  426. * @param feats features
  427. * @param x current x position
  428. * @param y current y position
  429. * @param z current z position
  430. * @return double distance
  431. **/
  432. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  433. /**
  434. * @brief clone operation instead of copy constructor (copy constructor does not work)
  435. **/
  436. virtual Operation3D* clone()
  437. {
  438. Operation3D* o = new Only13D();
  439. o->setContext(context);
  440. return o;
  441. }
  442. /**
  443. * @brief print some infos about operation extraction type
  444. * @return string feature type
  445. **/
  446. virtual std::string writeInfos()
  447. {
  448. std::string out = "Only1";
  449. if ( context )
  450. out = "(C)" + out;
  451. else
  452. out = "(R)" + out;
  453. return out + " " + Operation3D::writeInfos();
  454. }
  455. /**
  456. * @brief return operation type (for store and restore)
  457. * @return OperationTypes
  458. **/
  459. virtual OperationTypes getOps()
  460. {
  461. if (context)
  462. return ONLY1_C;
  463. else
  464. return ONLY1;
  465. }
  466. };
  467. /**
  468. * @brief get current relative x position
  469. **/
  470. class RelativeXPosition3D: public Operation3D
  471. {
  472. public:
  473. /**
  474. * @brief interface for feature computation
  475. * @param feats features
  476. * @param x current x position
  477. * @param y current y position
  478. * @param z current z position
  479. * @return double distance
  480. **/
  481. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  482. /**
  483. * @brief clone operation instead of copy constructor (copy constructor does not work)
  484. **/
  485. virtual Operation3D* clone()
  486. {
  487. Operation3D* o = new RelativeXPosition3D();
  488. o->setContext(context);
  489. return o;
  490. }
  491. /**
  492. * @brief print some infos about operation extraction type
  493. * @return string feature type
  494. **/
  495. virtual std::string writeInfos()
  496. {
  497. std::string out = "RelXPos";
  498. if ( context )
  499. out = "(C)" + out;
  500. else
  501. out = "(R)" + out;
  502. return out + " " + Operation3D::writeInfos();
  503. }
  504. /**
  505. * @brief return operation type (for store and restore)
  506. * @return OperationTypes
  507. **/
  508. virtual OperationTypes getOps()
  509. {
  510. return RELATIVEXPOSITION;
  511. }
  512. };
  513. /**
  514. * @brief get current relative y position
  515. **/
  516. class RelativeYPosition3D: public Operation3D
  517. {
  518. public:
  519. /**
  520. * @brief interface for feature computation
  521. * @param feats features
  522. * @param x current x position
  523. * @param y current y position
  524. * @param z current z position
  525. * @return double distance
  526. **/
  527. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  528. /**
  529. * @brief clone operation instead of copy constructor (copy constructor does not work)
  530. **/
  531. virtual Operation3D* clone()
  532. {
  533. Operation3D* o = new RelativeYPosition3D();
  534. o->setContext(context);
  535. return o;
  536. }
  537. /**
  538. * @brief print some infos about operation extraction type
  539. * @return string feature type
  540. **/
  541. virtual std::string writeInfos()
  542. {
  543. std::string out = "RelYPos";
  544. if ( context )
  545. out = "(C)" + out;
  546. else
  547. out = "(R)" + out;
  548. return out + " " + Operation3D::writeInfos();
  549. }
  550. /**
  551. * @brief return operation type (for store and restore)
  552. * @return OperationTypes
  553. **/
  554. virtual OperationTypes getOps()
  555. {
  556. return RELATIVEYPOSITION;
  557. }
  558. };
  559. /**
  560. * @brief get current relative z position
  561. **/
  562. class RelativeZPosition3D: public Operation3D
  563. {
  564. public:
  565. /**
  566. * @brief interface for feature computation
  567. * @param feats features
  568. * @param x current x position
  569. * @param y current y position
  570. * @param z current z position
  571. * @return double distance
  572. **/
  573. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  574. /**
  575. * @brief clone operation instead of copy constructor (copy constructor does not work)
  576. **/
  577. virtual Operation3D* clone()
  578. {
  579. Operation3D* o = new RelativeZPosition3D();
  580. o->setContext(context);
  581. return o;
  582. }
  583. /**
  584. * @brief print some infos about operation extraction type
  585. * @return string feature type
  586. **/
  587. virtual std::string writeInfos()
  588. {
  589. std::string out = "RelZPos";
  590. if ( context )
  591. out = "(C)" + out;
  592. else
  593. out = "(R)" + out;
  594. return out + " " + Operation3D::writeInfos();
  595. }
  596. /**
  597. * @brief return operation type (for store and restore)
  598. * @return OperationTypes
  599. **/
  600. virtual OperationTypes getOps()
  601. {
  602. return RELATIVEZPOSITION;
  603. }
  604. };
  605. /**
  606. * @brief uses mean in a window given by (x1,y1,z1) (x2,y2,z2)
  607. **/
  608. class IntegralOps3D: public Operation3D
  609. {
  610. public:
  611. /**
  612. * @brief set all parameters
  613. * @param _x1 position 1
  614. * @param _y1 position 1
  615. * @param _z1 position 1
  616. * @param _x2 position 2
  617. * @param _y2 position 2
  618. * @param _z2 position 2
  619. * @param _channel1 channel 1
  620. * @param _channel2 channel 2
  621. * @param _ftype feature type
  622. * @return void nothing
  623. **/
  624. virtual void set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, int _channel1, int _channel2, int _ftype );
  625. /**
  626. * @brief interface for feature computation
  627. * @param feats features
  628. * @param x current x position
  629. * @param y current y position
  630. * @param z current z position
  631. * @return double distance
  632. **/
  633. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  634. /**
  635. * @brief clone operation instead of copy constructor (copy constructor does not work)
  636. **/
  637. virtual Operation3D* clone()
  638. {
  639. Operation3D* o = new IntegralOps3D();
  640. o->setContext(context);
  641. return o;
  642. }
  643. /**
  644. * @brief print some infos about operation extraction type
  645. * @return string feature type
  646. **/
  647. virtual std::string writeInfos()
  648. {
  649. std::string out = "IntegralOps";
  650. if ( context )
  651. out = "(C)" + out;
  652. else
  653. out = "(R)" + out;
  654. return out + " " + Operation3D::writeInfos();
  655. }
  656. /**
  657. * @brief return operation type (for store and restore)
  658. * @return OperationTypes
  659. **/
  660. virtual OperationTypes getOps()
  661. {
  662. if (context)
  663. return INTEGRAL_C;
  664. else
  665. return INTEGRAL;
  666. }
  667. };
  668. /**
  669. * @brief uses mean in a window given by (x1,y1,z1) (x2,y2,z2) and full window
  670. **/
  671. class BiIntegralOps3D: public IntegralOps3D
  672. {
  673. public:
  674. /**
  675. * @brief interface for feature computation
  676. * @param feats features
  677. * @param x current x position
  678. * @param y current y position
  679. * @param z current z position
  680. * @return double distance
  681. **/
  682. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  683. /**
  684. * @brief clone operation instead of copy constructor (copy constructor does not work)
  685. **/
  686. virtual Operation3D* clone()
  687. {
  688. Operation3D* o = new BiIntegralOps3D();
  689. o->setContext(context);
  690. return o;
  691. }
  692. /**
  693. * @brief print some infos about operation extraction type
  694. * @return string feature type
  695. **/
  696. virtual std::string writeInfos()
  697. {
  698. std::string out = "BiIntegralOps";
  699. if ( context )
  700. out = "(C)" + out;
  701. else
  702. out = "(R)" + out;
  703. return out + " " + Operation3D::writeInfos();
  704. }
  705. /**
  706. * @brief return operation type (for store and restore)
  707. * @return OperationTypes
  708. **/
  709. virtual OperationTypes getOps()
  710. {
  711. if (context)
  712. return BIINTEGRAL_C;
  713. else
  714. return BIINTEGRAL;
  715. }
  716. };
  717. /**
  718. * @brief like a global bag of words to model the current appearance of classes in an image without local context
  719. **/
  720. class GlobalFeats3D: public IntegralOps3D
  721. {
  722. public:
  723. /**
  724. * @brief interface for feature computation
  725. * @param feats features
  726. * @param x current x position
  727. * @param y current y position
  728. * @param z current z position
  729. * @return double distance
  730. **/
  731. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  732. /**
  733. * @brief clone operation instead of copy constructor (copy constructor does not work)
  734. **/
  735. virtual Operation3D* clone()
  736. {
  737. Operation3D* o = new GlobalFeats3D();
  738. o->setContext(context);
  739. return o;
  740. }
  741. /**
  742. * @brief print some infos about operation extraction type
  743. * @return string feature type
  744. **/
  745. virtual std::string writeInfos()
  746. {
  747. std::string out = "GlobalFeats";
  748. if ( context )
  749. out = "(C)" + out;
  750. else
  751. out = "(R)" + out;
  752. return out + " " + Operation3D::writeInfos();
  753. }
  754. /**
  755. * @brief return operation type (for store and restore)
  756. * @return OperationTypes
  757. **/
  758. virtual OperationTypes getOps()
  759. {
  760. if ( context )
  761. return GLOBALFEATS_C;
  762. else
  763. return GLOBALFEATS;
  764. }
  765. };
  766. /**
  767. * @brief uses mean of Integral image given by x1, y1, z1 with current pixel as center
  768. **/
  769. class IntegralCenteredOps3D: public IntegralOps3D
  770. {
  771. public:
  772. /**
  773. * @brief set all parameters
  774. * @param _x1 position 1
  775. * @param _y1 position 1
  776. * @param _z1 position 1
  777. * @param _x2 position 2
  778. * @param _y2 position 2
  779. * @param _z2 position 2
  780. * @param _channel1 channel 1
  781. * @param _channel2 channel 2
  782. * @param _ftype feature type
  783. * @return void nothing
  784. **/
  785. virtual void set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, int _channel1, int _channel2, int _ftype );
  786. /**
  787. * @brief interface for feature computation
  788. * @param feats features
  789. * @param x current x position
  790. * @param y current y position
  791. * @param z current z position
  792. * @return double distance
  793. **/
  794. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  795. /**
  796. * @brief clone operation instead of copy constructor (copy constructor does not work)
  797. **/
  798. virtual Operation3D* clone()
  799. {
  800. Operation3D* o = new IntegralCenteredOps3D();
  801. o->setContext(context);
  802. return o;
  803. }
  804. /**
  805. * @brief print some infos about operation extraction type
  806. * @return string feature type
  807. **/
  808. virtual std::string writeInfos()
  809. {
  810. std::string out = "IntegralCenteredOps";
  811. if ( context )
  812. out = "(C)" + out;
  813. else
  814. out = "(R)" + out;
  815. return out + " " + Operation3D::writeInfos();
  816. }
  817. /**
  818. * @brief return operation type (for store and restore)
  819. * @return OperationTypes
  820. **/
  821. virtual OperationTypes getOps()
  822. {
  823. if ( context )
  824. return INTEGRALCENT_C;
  825. else
  826. return INTEGRALCENT;
  827. }
  828. };
  829. /**
  830. * @brief uses different of mean of Integral image given by two windows, where (x1,y1,z1) is the width, height & depth of window1 and (x2,y2,z2) of window 2
  831. **/
  832. class BiIntegralCenteredOps3D: public IntegralCenteredOps3D
  833. {
  834. public:
  835. /**
  836. * @brief set all parameters
  837. * @param _x1 position 1
  838. * @param _y1 position 1
  839. * @param _z1 position 1
  840. * @param _x2 position 2
  841. * @param _y2 position 2
  842. * @param _z2 position 2
  843. * @param _channel1 channel 1
  844. * @param _channel2 channel 2
  845. * @param _ftype feature type
  846. * @return void nothing
  847. **/
  848. virtual void set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, int _channel1, int _channel2, int ftype );
  849. /**
  850. * @brief interface for feature computation
  851. * @param feats features
  852. * @param x current x position
  853. * @param y current y position
  854. * @param z current z position
  855. * @return double distance
  856. **/
  857. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  858. /**
  859. * @brief clone operation instead of copy constructor (copy constructor does not work)
  860. **/
  861. virtual Operation3D* clone()
  862. {
  863. Operation3D* o = new BiIntegralCenteredOps3D();
  864. o->setContext(context);
  865. return o;
  866. }
  867. /**
  868. * @brief print some infos about operation extraction type
  869. * @return string feature type
  870. **/
  871. virtual std::string writeInfos()
  872. {
  873. std::string out = "BiIntegralCenteredOps";
  874. if ( context )
  875. out = "(C)" + out;
  876. else
  877. out = "(R)" + out;
  878. return out + Operation3D::writeInfos();
  879. }
  880. /**
  881. * @brief return operation type (for store and restore)
  882. * @return OperationTypes
  883. **/
  884. virtual OperationTypes getOps()
  885. {
  886. if ( context )
  887. return BIINTEGRALCENT_C;
  888. else
  889. return BIINTEGRALCENT;
  890. }
  891. };
  892. /**
  893. * @brief horizontal Haar features
  894. * ++
  895. * --
  896. **/
  897. class HaarHorizontal3D: public IntegralCenteredOps3D
  898. {
  899. public:
  900. /**
  901. * @brief interface for feature computation
  902. * @param feats features
  903. * @param x current x position
  904. * @param y current y position
  905. * @param z current z position
  906. * @return double distance
  907. **/
  908. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  909. /**
  910. * @brief clone operation instead of copy constructor (copy constructor does not work)
  911. **/
  912. virtual Operation3D* clone()
  913. {
  914. Operation3D* o = new HaarHorizontal3D();
  915. o->setContext(context);
  916. return o;
  917. }
  918. /**
  919. * @brief print some infos about operation extraction type
  920. * @return string feature type
  921. **/
  922. virtual std::string writeInfos()
  923. {
  924. std::string out = "HaarHorizontal";
  925. if ( context )
  926. out = "(C)" + out;
  927. else
  928. out = "(R)" + out;
  929. return out + " " + Operation3D::writeInfos();
  930. }
  931. /**
  932. * @brief return operation type (for store and restore)
  933. * @return OperationTypes
  934. **/
  935. virtual OperationTypes getOps()
  936. {
  937. if ( context )
  938. return HAARHORIZ_C;
  939. else
  940. return HAARHORIZ;
  941. }
  942. };
  943. /**
  944. * @brief vertical Haar features
  945. * +-
  946. * +-
  947. **/
  948. class HaarVertical3D: public IntegralCenteredOps3D
  949. {
  950. public:
  951. /**
  952. * @brief interface for feature computation
  953. * @param feats features
  954. * @param x current x position
  955. * @param y current y position
  956. * @param z current z position
  957. * @return double distance
  958. **/
  959. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  960. /**
  961. * @brief clone operation instead of copy constructor (copy constructor does not work)
  962. **/
  963. virtual Operation3D* clone()
  964. {
  965. Operation3D* o = new HaarVertical3D();
  966. o->setContext(context);
  967. return o;
  968. }
  969. /**
  970. * @brief print some infos about operation extraction type
  971. * @return string feature type
  972. **/
  973. virtual std::string writeInfos()
  974. {
  975. std::string out = "HaarVertical";
  976. if ( context )
  977. out = "(C)" + out;
  978. else
  979. out = "(R)" + out;
  980. return out + " " + Operation3D::writeInfos();
  981. }
  982. /**
  983. * @brief return operation type (for store and restore)
  984. * @return OperationTypes
  985. **/
  986. virtual OperationTypes getOps()
  987. {
  988. if ( context )
  989. return HAARVERT_C;
  990. else
  991. return HAARVERT;
  992. }
  993. };
  994. /**
  995. * @brief stacked (depth) Haar features
  996. * +-
  997. * +-
  998. **/
  999. class HaarStacked3D: public IntegralCenteredOps3D
  1000. {
  1001. public:
  1002. /**
  1003. * @brief interface for feature computation
  1004. * @param feats features
  1005. * @param x current x position
  1006. * @param y current y position
  1007. * @param z current z position
  1008. * @return double distance
  1009. **/
  1010. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  1011. /**
  1012. * @brief clone operation instead of copy constructor (copy constructor does not work)
  1013. **/
  1014. virtual Operation3D* clone()
  1015. {
  1016. Operation3D* o = new HaarStacked3D();
  1017. o->setContext(context);
  1018. return o;
  1019. }
  1020. /**
  1021. * @brief print some infos about operation extraction type
  1022. * @return string feature type
  1023. **/
  1024. virtual std::string writeInfos()
  1025. {
  1026. std::string out = "HaarStacked";
  1027. if ( context )
  1028. out = "(C)" + out;
  1029. else
  1030. out = "(R)" + out;
  1031. return out + " " + Operation3D::writeInfos();
  1032. }
  1033. /**
  1034. * @brief return operation type (for store and restore)
  1035. * @return OperationTypes
  1036. **/
  1037. virtual OperationTypes getOps()
  1038. {
  1039. if ( context )
  1040. return HAARSTACK_C;
  1041. else
  1042. return HAARSTACK;
  1043. }
  1044. };
  1045. /**
  1046. * @brief x-y diagonal Haar features
  1047. * +-
  1048. * -+
  1049. **/
  1050. class HaarDiagXY3D: public IntegralCenteredOps3D
  1051. {
  1052. public:
  1053. /**
  1054. * @brief interface for feature computation
  1055. * @param feats features
  1056. * @param x current x position
  1057. * @param y current y position
  1058. * @param z current z position
  1059. * @return double distance
  1060. **/
  1061. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  1062. /**
  1063. * @brief clone operation instead of copy constructor (copy constructor does not work)
  1064. **/
  1065. virtual Operation3D* clone()
  1066. {
  1067. Operation3D* o = new HaarDiagXY3D();
  1068. o->setContext(context);
  1069. return o;
  1070. }
  1071. /**
  1072. * @brief print some infos about operation extraction type
  1073. * @return string feature type
  1074. **/
  1075. virtual std::string writeInfos()
  1076. {
  1077. std::string out = "HaarDiagXY";
  1078. if ( context )
  1079. out = "(C)" + out;
  1080. else
  1081. out = "(R)" + out;
  1082. return out + " " + Operation3D::writeInfos();
  1083. }
  1084. /**
  1085. * @brief return operation type (for store and restore)
  1086. * @return OperationTypes
  1087. **/
  1088. virtual OperationTypes getOps()
  1089. {
  1090. if ( context )
  1091. return HAARDIAGXY_C;
  1092. else
  1093. return HAARDIAGXY;
  1094. }
  1095. };
  1096. /**
  1097. * @brief x-z diagonal Haar features
  1098. * +-
  1099. * -+
  1100. **/
  1101. class HaarDiagXZ3D: public IntegralCenteredOps3D
  1102. {
  1103. public:
  1104. /**
  1105. * @brief interface for feature computation
  1106. * @param feats features
  1107. * @param x current x position
  1108. * @param y current y position
  1109. * @param z current z position
  1110. * @return double distance
  1111. **/
  1112. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  1113. /**
  1114. * @brief clone operation instead of copy constructor (copy constructor does not work)
  1115. **/
  1116. virtual Operation3D* clone()
  1117. {
  1118. Operation3D* o = new HaarDiagXZ3D();
  1119. o->setContext(context);
  1120. return o;
  1121. }
  1122. /**
  1123. * @brief print some infos about operation extraction type
  1124. * @return string feature type
  1125. **/
  1126. virtual std::string writeInfos()
  1127. {
  1128. std::string out = "HaarDiagXZ";
  1129. if ( context )
  1130. out = "(C)" + out;
  1131. else
  1132. out = "(R)" + out;
  1133. return out + " " + Operation3D::writeInfos();
  1134. }
  1135. /**
  1136. * @brief return operation type (for store and restore)
  1137. * @return OperationTypes
  1138. **/
  1139. virtual OperationTypes getOps()
  1140. {
  1141. if ( context )
  1142. return HAARDIAGXZ_C;
  1143. else
  1144. return HAARDIAGXZ;
  1145. }
  1146. };
  1147. /**
  1148. * @brief y-z diagonal Haar features
  1149. * +-
  1150. * -+
  1151. **/
  1152. class HaarDiagYZ3D: public IntegralCenteredOps3D
  1153. {
  1154. public:
  1155. /**
  1156. * @brief interface for feature computation
  1157. * @param feats features
  1158. * @param x current x position
  1159. * @param y current y position
  1160. * @param z current z position
  1161. * @return double distance
  1162. **/
  1163. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  1164. /**
  1165. * @brief clone operation instead of copy constructor (copy constructor does not work)
  1166. **/
  1167. virtual Operation3D* clone()
  1168. {
  1169. Operation3D* o = new HaarDiagYZ3D();
  1170. o->setContext(context);
  1171. return o;
  1172. }
  1173. /**
  1174. * @brief print some infos about operation extraction type
  1175. * @return string feature type
  1176. **/
  1177. virtual std::string writeInfos()
  1178. {
  1179. std::string out = "HaarDiagYZ";
  1180. if ( context )
  1181. out = "(C)" + out;
  1182. else
  1183. out = "(R)" + out;
  1184. return out + " " + Operation3D::writeInfos();
  1185. }
  1186. /**
  1187. * @brief return operation type (for store and restore)
  1188. * @return OperationTypes
  1189. **/
  1190. virtual OperationTypes getOps()
  1191. {
  1192. if ( context )
  1193. return HAARDIAGYZ_C;
  1194. else
  1195. return HAARDIAGYZ;
  1196. }
  1197. };
  1198. /**
  1199. * @brief horizontal Haar features
  1200. * +++
  1201. * ---
  1202. * +++
  1203. */
  1204. class Haar3Horiz3D: public BiIntegralCenteredOps3D
  1205. {
  1206. public:
  1207. /**
  1208. * @brief interface for feature computation
  1209. * @param feats features
  1210. * @param x current x position
  1211. * @param y current y position
  1212. * @param z current z position
  1213. * @return double distance
  1214. **/
  1215. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  1216. /**
  1217. * @brief clone operation instead of copy constructor (copy constructor does not work)
  1218. **/
  1219. virtual Operation3D* clone()
  1220. {
  1221. Operation3D* o = new Haar3Horiz3D();
  1222. o->setContext(context);
  1223. return o;
  1224. }
  1225. /**
  1226. * @brief print some infos about operation extraction type
  1227. * @return string feature type
  1228. **/
  1229. virtual std::string writeInfos()
  1230. {
  1231. std::string out = "Haar3Horiz";
  1232. if ( context )
  1233. out = "(C)" + out;
  1234. else
  1235. out = "(R)" + out;
  1236. return out + " " + Operation3D::writeInfos();
  1237. }
  1238. /**
  1239. * @brief return operation type (for store and restore)
  1240. * @return OperationTypes
  1241. **/
  1242. virtual OperationTypes getOps()
  1243. {
  1244. if ( context )
  1245. return HAAR3HORIZ_C;
  1246. else
  1247. return HAAR3HORIZ;
  1248. }
  1249. };
  1250. /**
  1251. * @brief vertical Haar features
  1252. * +-+
  1253. * +-+
  1254. * +-+
  1255. */
  1256. class Haar3Vert3D: public BiIntegralCenteredOps3D
  1257. {
  1258. public:
  1259. /**
  1260. * @brief interface for feature computation
  1261. * @param feats features
  1262. * @param x current x position
  1263. * @param y current y position
  1264. * @param z current z position
  1265. * @return double distance
  1266. **/
  1267. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  1268. /**
  1269. * @brief clone operation instead of copy constructor (copy constructor does not work)
  1270. **/
  1271. virtual Operation3D* clone()
  1272. {
  1273. Operation3D* o = new Haar3Vert3D();
  1274. o->setContext(context);
  1275. return o;
  1276. }
  1277. /**
  1278. * @brief print some infos about operation extraction type
  1279. * @return string feature type
  1280. **/
  1281. virtual std::string writeInfos()
  1282. {
  1283. std::string out = "Haar3Vert";
  1284. if ( context )
  1285. out = "(C)" + out;
  1286. else
  1287. out = "(R)" + out;
  1288. return out + " " + Operation3D::writeInfos();
  1289. }
  1290. /**
  1291. * @brief return operation type (for store and restore)
  1292. * @return OperationTypes
  1293. **/
  1294. virtual OperationTypes getOps()
  1295. {
  1296. if ( context )
  1297. return HAAR3VERT_C;
  1298. else
  1299. return HAAR3VERT;
  1300. }
  1301. };
  1302. /**
  1303. * @brief stacked Haar features
  1304. * +-+
  1305. * +-+
  1306. * +-+
  1307. */
  1308. class Haar3Stack3D: public BiIntegralCenteredOps3D
  1309. {
  1310. public:
  1311. /**
  1312. * @brief interface for feature computation
  1313. * @param feats features
  1314. * @param x current x position
  1315. * @param y current y position
  1316. * @param z current z position
  1317. * @return double distance
  1318. **/
  1319. virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
  1320. /**
  1321. * @brief clone operation instead of copy constructor (copy constructor does not work)
  1322. **/
  1323. virtual Operation3D* clone()
  1324. {
  1325. Operation3D* o = new Haar3Stack3D();
  1326. o->setContext(context);
  1327. return o;
  1328. }
  1329. /**
  1330. * @brief print some infos about operation extraction type
  1331. * @return string feature type
  1332. **/
  1333. virtual std::string writeInfos()
  1334. {
  1335. std::string out = "Haar3Stack";
  1336. if ( context )
  1337. out = "(C)" + out;
  1338. else
  1339. out = "(R)" + out;
  1340. return out + " " + Operation3D::writeInfos();
  1341. }
  1342. /**
  1343. * @brief return operation type (for store and restore)
  1344. * @return OperationTypes
  1345. **/
  1346. virtual OperationTypes getOps()
  1347. {
  1348. if ( context )
  1349. return HAAR3STACK_C;
  1350. else
  1351. return HAAR3STACK;
  1352. }
  1353. };
  1354. } //end namespace