sprk_ooc.h
1 // Copyright (c) Tech Soft 3D, Inc.
2 //
3 // The information contained herein is confidential and proprietary to Tech Soft 3D, Inc.,
4 // and considered a trade secret as defined under civil and criminal statutes.
5 // Tech Soft 3D, Inc. shall pursue its civil and criminal remedies in the event of
6 // unauthorized use or misappropriation of its trade secrets. Use of this information
7 // by anyone other than authorized employees of Tech Soft 3D, Inc. is granted only under
8 // a written non-disclosure agreement, expressly prescribing the scope and manner of such use.
9 
10 #ifndef SPRK_OOC_H
11 #define SPRK_OOC_H
12 
13 #include "sprk.h"
14 
15 #ifdef _MSC_VER
16 #ifndef STATIC_APP
17 # ifdef SPRK_OOC
18 # define OOC_API __declspec (dllexport)
19 # else
20 # define OOC_API __declspec (dllimport)
21 # endif
22 #endif
23 #else
24 # include <stddef.h>
25 #endif
26 
27 #ifndef OOC_API
28 # define OOC_API
29 #endif
30 
31 #include <mutex>
32 
33 
34 class HBaseView;
35 
36 namespace HPS
37 {
39 class OOC_API OOC
40 {
41 public:
42 
44  class Area {
45  public:
46  Area() {}
47  Area(HPS::Rectangle const & in_rect,
48  HPS::MatrixKit const & in_world_to_window,
49  const char * in_name)
50  : window_min(in_rect.left, in_rect.bottom, 0),
51  window_max(in_rect.right, in_rect.top, 0),
52  world_to_window(in_world_to_window),
53  name(in_name)
54  {
55  }
56 
60  bool Intersects(HPS::SimpleCuboid const & world_space_bounding) const
61  {
62  HPS::Point world_bounds[8];
63  world_space_bounding.Generate_Cuboid_Points(world_bounds);
64 
65  auto window_bounds = world_to_window.Transform(8, world_bounds);
66 
67  HPS::Point window_min_bound = window_bounds[0];
68  for (HPS::Point const & window_bound : window_bounds) {
69  if (window_bound.x < window_min_bound.x)
70  window_min_bound.x = window_bound.x;
71  if (window_bound.y < window_min_bound.y)
72  window_min_bound.y = window_bound.y;
73  }
74 
75  HPS::Point window_max_bound = window_bounds[0];
76  for (HPS::Point const & window_bound : window_bounds) {
77  if (window_bound.x > window_max_bound.x)
78  window_max_bound.x = window_bound.x;
79  if (window_bound.y > window_max_bound.y)
80  window_max_bound.y = window_bound.y;
81  }
82 
83  if (window_max.x < window_min_bound.x)
84  return false;
85 
86  if (window_min.x > window_max_bound.x)
87  return false;
88 
89  if (window_max.y < window_min_bound.y)
90  return false;
91 
92  if (window_min.y > window_max_bound.y)
93  return false;
94 
95  return true;
96  }
97 
101  bool Intersects(HPS::Point const & world_space_point) const
102  {
103  HPS::Point window_point = world_to_window.Transform(world_space_point);
104 
105  if (window_point.x < window_min.x)
106  return false;
107 
108  if (window_point.y < window_min.y)
109  return false;
110 
111  if (window_point.x > window_max.x)
112  return false;
113 
114  if (window_point.y > window_max.y)
115  return false;
116 
117  return true;
118  }
119 
120  HPS::Point const & GetWindowMin() const { return window_min; }
121 
122  HPS::Point const & GetWindowMax() const { return window_max; }
123 
125  HPS::MatrixKit const & GetWorldToWindow() const { return world_to_window; }
126 
128  HPS::UTF8 const & GetName() const { return name; }
129 
130  protected:
131  HPS::Point window_min;
132  HPS::Point window_max;
133  HPS::MatrixKit world_to_window;
134  HPS::UTF8 name;
135  };
136 
137  typedef std::vector<Area, HPS::Allocator<Area>> AreaArray;
138 
139  class PointCloud;
140 
142  class OOC_API AreaHighlightTracker {
143 
144  public:
145  AreaHighlightTracker(HPS::Canvas const & in_canvas, HPS::SegmentKey const & in_area_cameras);
146 
147  virtual ~AreaHighlightTracker();
148 
149  virtual void Process(HPS::KeyArray const & shell_keys)
150  {
151  (void)shell_keys;
152  }
153 
155  void Clear();
156 
158  bool Empty() const;
159 
164  void AddArea(HPS::Rectangle const & in_rect, HPS::MatrixKit const & in_world_to_window, bool in_clear);
165 
166 
170  void AddPoint(HPS::WorldPoint const & in_point, bool in_clear);
171 
175  bool Intersects(HPS::SimpleCuboid const & world_space_bounding) const;
176 
180  bool Intersects(HPS::Point const & world_space_point) const;
181 
183  HPS::OOC::AreaArray const & GetAreas() const;
184 
186  HPS::Canvas const & GetCanvas() const;
187 
189  HPS::WindowKey const & GetWindowKey() const;
190 
192  HPS::SegmentKey const & GetAreaCameraSegment() const;
193 
194  bool GetInspecting() const;
195 
196  private:
197  friend class HBaseView;
198  friend class PointCloud;
199  void * opaque;
200  };
201 
203  class OOC_API ImportNotifier : public IONotifier
204  {
205  public:
207  ImportNotifier();
208 
211  ImportNotifier(ImportNotifier const & in_that);
212 
217  ImportNotifier(IONotifier const & in_that);
218 
222  ImportNotifier(ImportNotifier && in_that);
223 
227  ImportNotifier & operator=(ImportNotifier && in_that);
228 
229  virtual ~ImportNotifier();
230 
231  static const HPS::Type staticType = HPS::Type::OOCImportNotifier;
232  HPS::Type ObjectType() const { return staticType; };
233 
237  ImportNotifier & operator=(ImportNotifier const & in_that);
238 
241  void Assign(ImportNotifier const & in_that);
242 
246  HPS::Model & GetTarget() const;
247  };
248 
250  class OOC_API ImportOptionsKit : public HPS::Sprocket
251  {
252  public:
255 
258  ImportOptionsKit(ImportOptionsKit const & in_kit);
259 
264 
268  ImportOptionsKit & operator=(ImportOptionsKit && in_that);
269 
270  virtual ~ImportOptionsKit();
271 
272  static const HPS::Type staticType = HPS::Type::OOCImportOptionsKit;
273  HPS::Type ObjectType() const { return staticType; }
274 
278  static ImportOptionsKit GetDefault();
279 
282  void Set(ImportOptionsKit const & in_kit);
283 
286  void Show(ImportOptionsKit & out_kit) const;
287 
291  ImportOptionsKit & operator=(ImportOptionsKit const & in_kit);
292 
295  bool Empty() const;
296 
300  bool Equals(ImportOptionsKit const & in_kit) const;
301 
305  bool operator==(ImportOptionsKit const & in_kit) const;
306 
310  bool operator!=(ImportOptionsKit const & in_kit) const;
311 
315  ImportOptionsKit & SetTarget(HPS::Model const & in_target);
316 
321  bool ShowTarget(HPS::Model & out_model) const;
322 
325  ImportOptionsKit & UnsetTarget();
326 
330  ImportOptionsKit & SetManualUpdates(bool in_manual_updates);
331 
335  bool ShowManualUpdates(bool & out_manual_updates) const;
336 
339  ImportOptionsKit & UnsetManualUpdates();
340 
344  ImportOptionsKit & SetCenterBounding(bool in_center_bounding);
345 
349  bool ShowCenterBounding(bool & out_center_bounding) const;
350 
353  ImportOptionsKit & UnsetCenterBounding();
354 
360  ImportOptionsKit & SetTranslation(double in_x, double in_y, double in_z);
361 
367  bool ShowTranslation(double & out_x, double & out_y, double & out_z) const;
368 
371  ImportOptionsKit & UnsetTranslation();
372 
377  ImportOptionsKit & SetAreaHighlightTracker(HPS::OOC::AreaHighlightTracker & in_area_highlight_tracker);
378 
381  ImportOptionsKit & UnsetAreaHighlightTracker();
382 
385  ImportOptionsKit & UnsetEverything();
386 
387  };
388 
389 
391  class OOC_API File
392  {
393  public:
398  static ImportNotifier Import(char const * in_file_name, ImportOptionsKit const & in_options);
399 
400  private:
402  File();
403  };
404 
407 
408 
409  class OOC_API PointCloud;
410  class OOC_API SynchronizedActions;
411  class OOC_API QueryFilter;
412  class OOC_API QueryIterator;
413  class OOC_API QueryResult;
414  class FilterForwarder;
415 
416  class OOC_API NodeHandle {
417  public:
418  public:
419  NodeHandle(NodeHandle&& that);
420  ~NodeHandle();
421 
422  bool Equals(NodeHandle const & other) const;
423  bool operator== (NodeHandle const & other) const;
424  bool operator!= (NodeHandle const & other) const;
425  NodeHandle& operator=(NodeHandle&& other);
426 
429  bool Empty() const;
430 
433  HPS::SegmentKey GetSegment() const;
434 
437  HPS::ShellKey GetShell() const;
438 
439  private:
441  NodeHandle();
442  NodeHandle(void * in_opaque);
443  NodeHandle(NodeHandle const & that) = delete;
444 
445  void * opaque;
446 
447  friend class HPS::OOC::SynchronizedActions;
448  friend class HPS::OOC::PointCloud;
449  friend class HPS::OOC::FilterForwarder;
450  friend class HPS::OOC::QueryIterator;
451  };
452 
454  class OOC_API SynchronizedActions {
455  public:
456 
458  enum class Result {
459  Success,
460  ErrorInvalidNode,
461  ErrorInvalidPointCloud,
462  ErrorUnknownFailure,
463  ErrorInternalFailure,
464  ErrorCouldNotFindNode,
465  ErrorInputIndicesAreNotStrictlyIncreasing,
466  ErrorIllegalInputIndices,
467  ErrorCorruptNode,
468  ErrorFileSystemFailure,
469  };
470 
474  Result DeleteNode(NodeHandle const & node_handle) const;
475 
481  Result DeleteSpecificPoints(NodeHandle const & node_handle, int32_t const point_indices[], size_t count) const;
482 
487  Result DeleteSpecificPoints(NodeHandle const & node_handle, HPS::Int32Array const & point_indices) const;
488 
491  Result OptimizeDeltas() const;
492 
493  private:
494  friend class HPS::OOC::PointCloud;
497  void * opaque;
498  };
499 
500 
502  class OOC_API Synchronized {
503  public:
504 
505  Synchronized();
506 
507  virtual ~Synchronized();
508 
513  (void)actions;
514  return HPS::OOC::SynchronizedActions::Result::Success;
515  };
516  };
517 
518 
520  enum class IOResult {
521  Success,
522  ErrorInvalidPointCloud,
523  ErrorUnknownFailure,
524  ErrorNoOOCView,
525  ErrorCyclicFileDependencies,
526  ErrorSerializationFailure,
527  ErrorDeserializationFailure,
528  ErrorIllegalFileName,
529  ErrorFileSystemFailure,
530  ErrorOOCRootAlreadyExists,
531  ErrorInvalidBuffer,
532  };
533 
534  typedef std::vector<PointCloud, HPS::Allocator<PointCloud>> PointCloudArray;
535 
536 
538  class OOC_API PointCloud {
539  public:
542  PointCloud();
543 
546  PointCloud(HPS::Model const & in_model);
547 
550  PointCloud(PointCloud&& that);
551  ~PointCloud();
552 
553  bool Equals(PointCloud const & other) const;
554  bool operator== (PointCloud const & other) const;
555  bool operator!= (PointCloud const & other) const;
556  PointCloud& operator=(PointCloud&& other);
557 
558 
561  bool Empty();
562 
565  HPS::SegmentKey GetSegment();
566 
568  void Destroy();
569 
571  void Release();
572 
576  NodeHandle GetNodeHandle(HPS::SegmentKey const & node_key);
577 
580  bool PollUpdateNeeded();
581 
585  HPS::OOC::SynchronizedActions::Result Synchronize(Synchronized & synchronized);
586 
590  OOC::QueryIterator QueryPoints(QueryFilter & filter);
591 
615  IOResult CommitDeltasToFile();
616 
617  /* Saves to disk any changes made to the point cloud.
618  \param delta_file_name The generated file name of the written delta will be returned.
619  \return an IOResult return code.
620  */
621  IOResult CommitDeltasToFile(HPS::UTF8 & out_delta_file_name);
622 
626  bool HasUncommittedDeltas();
627 
631  bool DeleteFromPointCloud(HPS::OOC::AreaHighlightTracker & tracker);
632 
636  static bool ShowPointClouds(HPS::Model const & in_model, HPS::OOC::PointCloudArray & out_point_clouds);
637 
638  private:
640  PointCloud(void * in_opaque);
641  PointCloud(PointCloud const & that) = delete;
642  void * opaque;
643  };
644 
647  class OOC_API QueryFilter {
648  friend class QueryIterator;
649 
650  public:
651  QueryFilter() {}
652  virtual ~QueryFilter() {}
653 
656  virtual bool RejectPointsInMemory()
657  {
658  return false;
659  }
660 
663  virtual bool RejectPointsOnDisk()
664  {
665  return false;
666  }
667 
671  virtual bool RejectNode(NodeHandle const & node_handle)
672  {
673  (void)node_handle;
674  return false;
675  }
676 
681  virtual bool RejectBounding(Point const & min_bound, Point const & max_bound)
682  {
683  (void)min_bound; (void)max_bound;
684  return false;
685  }
686 
691  virtual bool AcceptPoint(Point const & point, size_t point_index)
692  {
693  (void)point; (void)point_index;
694  return true;
695  }
696  };
697 
698 
700  class OOC_API QueryIterator {
701 
702  public:
704  enum class Status {
705  Alive,
706  Dead,
707  ErrorUnknownFailure,
708  ErrorFileSystemFailure,
709  ErrorDeserializationFailure,
710  ErrorCouldNotFindNode,
711  ErrorCorruptNode,
712  };
713 
716  QueryIterator();
717 
720  QueryIterator(QueryIterator && other);
721 
722  QueryIterator& operator=(QueryIterator&& other);
723 
724  ~QueryIterator();
725 
728  Status GetStatus() const;
729 
731  enum class Storage {
732  Memory,
733  Disk,
734  };
735 
738  NodeHandle GetNodeHandle() const;
739 
742  RGBColor GetNodePointColor() const;
743 
746  Point GetNodePoint() const;
747 
750  size_t GetNodePointIndex() const;
751 
754  Storage GetStorage() const;
755 
758  void Next();
759 
760  private:
761  friend class HPS::OOC::PointCloud;
762  QueryIterator(void * in_opaque);
763  QueryIterator(QueryIterator const & other) = delete;
764  void * opaque;
765  };
766 
767 private:
769  OOC();
770 };
771 
772 }
773 
774 #endif
Definition: hps.h:85
Definition: sprk_ooc.h:538
Definition: sprk_ooc.h:700
HPS::Type ObjectType() const
Definition: sprk_ooc.h:232
Definition: sprk.h:68
Definition: hps.h:49265
Definition: sprk.h:936
Result
Definition: sprk_ooc.h:458
virtual bool RejectPointsInMemory()
Definition: sprk_ooc.h:656
Definition: sprk_ooc.h:39
virtual HPS::OOC::SynchronizedActions::Result Actions(SynchronizedActions const &actions)
Definition: sprk_ooc.h:512
Definition: hps.h:7929
HPS_INLINE void Generate_Cuboid_Points(Point_3D< F > *points) const
Definition: hps.h:4071
Definition: hps.h:3640
Status
Definition: sprk_ooc.h:704
virtual bool AcceptPoint(Point const &point, size_t point_index)
Definition: sprk_ooc.h:691
Definition: sprk_ooc.h:454
Definition: sprk_ooc.h:250
HPS::Type ObjectType() const
Definition: sprk_ooc.h:273
Definition: hps.h:33767
Definition: sprk_ooc.h:647
virtual bool RejectNode(NodeHandle const &node_handle)
Definition: sprk_ooc.h:671
HPS::MatrixKit const & GetWorldToWindow() const
Definition: sprk_ooc.h:125
Definition: hps.h:4547
Definition: hps.h:7300
Definition: sprk_ooc.h:391
virtual bool RejectBounding(Point const &min_bound, Point const &max_bound)
Definition: sprk_ooc.h:681
Definition: hps.h:6252
bool Intersects(HPS::Point const &world_space_point) const
Definition: sprk_ooc.h:101
bool Intersects(HPS::SimpleCuboid const &world_space_bounding) const
Definition: sprk_ooc.h:60
Definition: hps.h:16019
HPS::UTF8 const & GetName() const
Definition: sprk_ooc.h:128
Definition: hps.h:49206
Definition: sprk_ooc.h:142
Definition: sprk.h:1318
IOResult
Definition: sprk_ooc.h:520
std::vector< Key, Allocator< Key > > KeyArray
Array of type HPS::Key.
Definition: hps.h:6856
Definition: sprk_ooc.h:502
Storage
Definition: sprk_ooc.h:731
Definition: sprk_ooc.h:203
Definition: hps.h:9331
virtual bool RejectPointsOnDisk()
Definition: sprk_ooc.h:663
Definition: sprk_ooc.h:44
Definition: sprk_ooc.h:416
std::vector< int32_t, Allocator< int32_t > > Int32Array
Array of type int32_t.
Definition: hps.h:6899
Definition: hps.h:5920