PointCloudAPI.h
Go to the documentation of this file.
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 #pragma once
11 
12 #include "hc.h"
13 #include "HTools.h"
14 #include "HGlobals.h"
15 #include "BStream.h"
16 
17 #include <stdint.h>
18 #include <functional>
19 
20 
22 
23 
24 #ifdef _WIN32
25 # define OOC_API __declspec(dllexport)
26 #else
27 # define OOC_API
28 #endif
29 
30 
32 
33 
35 class PointCloudWorld;
36 class NodeData;
37 
38 
39 namespace ooc
40 {
41  namespace delta
42  {
43  namespace on_disk
44  {
45  class NodeHandleSerializer;
46  class NodeHandleDeserializer;
47  }
48  }
49 }
50 
51 
53 
54 
55 namespace ooc
56 {
57  class ReifiedEnv;
58 
59 
61  class OOC_API Env {
62  friend class ReifiedEnv;
63 
64  public:
69  Env ();
70 
71  bool operator== (Env const & other) const;
72  bool operator!= (Env const & other) const;
73 
74  private:
75  void * opaque;
76  uintptr_t key;
77  };
78 
79 
81  class OOC_API RGBColor {
82  public:
85  : r(-1.0f)
86  , g(-1.0f)
87  , b(-1.0f)
88  {}
89 
91  RGBColor(float r, float g, float b)
92  : r(r)
93  , g(g)
94  , b(b)
95  {}
96 
98  bool IsValid () const {
99  return r >= 0.0f && g >= 0.0f && b >= 0.0f;
100  }
101 
102  public:
103  float r;
104  float g;
105  float b;
106  };
107 
108 
110  class OOC_API Point {
111  public:
113  Point ()
114  : x(0.0f)
115  , y(0.0f)
116  , z(0.0f)
117  {}
118 
125  Point (float x, float y, float z)
126  : x(x)
127  , y(y)
128  , z(z)
129  {}
130 
135  Point operator+ (Point const & other) const
136  {
137  return Point(x + other.x, y + other.y, z + other.z);
138  }
139 
144  Point operator- (Point const & other) const
145  {
146  return Point(x - other.x, y - other.y, z - other.z);
147  }
148 
153  Point operator* (float scale) const
154  {
155  return Point(x * scale, y * scale, z * scale);
156  }
157 
162  Point operator/ (float scale) const
163  {
164  return Point(x / scale, y / scale, z / scale);
165  }
166 
167  public:
168  float x;
169  float y;
170  float z;
171  };
172 
176  friend class delta::on_disk::NodeHandleSerializer;
177  friend class delta::on_disk::NodeHandleDeserializer;
178 
179  private:
180  NodeHandle (uint32_t node_file_id, uint32_t node_file_offset);
181 
182  public:
185 
189  NodeHandle (NodeData const & node_data);
190 
196  static NodeHandle Invalid ();
197 
198  /* Returns a hash code for a given node handle. Provides a means to hash the
199  value of an ooc::NodeHandle.
200 
201  A node handle will always return the same hash value in a given run of a
202  program. That being said, this function may return different values between
203  different runs of the program. In other words, the generated hash code is
204  not persistent between different program executions.
205  */
206  size_t Hash () const;
207 
213  bool operator== (NodeHandle const & other) const
214  {
215  return node_file_id == other.node_file_id && node_file_offset == other.node_file_offset;
216  }
217 
223  bool operator!= (NodeHandle const & other) const
224  {
225  return !(*this == other);
226  }
227 
233  bool operator< (NodeHandle const & other) const
234  {
235  if (node_file_id < other.node_file_id) {
236  return true;
237  }
238  if (node_file_id > other.node_file_id) {
239  return false;
240  }
241  return node_file_offset < other.node_file_offset;
242  }
243 
244  private:
245  uint32_t node_file_id;
246  uint32_t node_file_offset;
247  };
248 
249 
255  OOC_API bool IsRoot (HC_KEY ooc_root);
256 
264  OOC_API bool GetEnv (HC_KEY ooc_root, Env & out_env);
265 
271  OOC_API HC_KEY GetRoot (Env env);
272 
283  OOC_API void Destroy (Env env);
284 
297  OOC_API void Release (Env env);
298 
308  OOC_API bool GetNodeHandle (Env env, HC_KEY node_segment_key, NodeHandle & out_node_handle);
309 
316  OOC_API HC_KEY GetSegmentKey (Env env, NodeHandle const & node_handle);
317 
327  OOC_API HC_KEY GetShellKey (Env env, NodeHandle const & node_handle);
328 
340 
347  OOC_API int Configure (char const * in, char * out);
348 
349 
350  namespace delta
351  {
353 
355  enum SyncResult {
357  };
358 
373  OOC_API SyncResult SynchronizeWith (Env, std::function<void(SyncToken const &)>);
374 
376  friend SyncResult SynchronizeWith (Env, std::function<void(SyncToken const &)>);
377 
378  private:
381 
382  PointCloudWorld & GetWorld () const;
383 
384  private:
385  void operator= (InternalSynchronizer const &);
386 
387  private:
388  PointCloudWorld & pcw;
389  };
390 
400  };
401 
410  OOC_API ModifyResult DeleteNode (SyncToken const & sync_token, NodeHandle const & node_handle);
411 
430  OOC_API ModifyResult DeleteSpecificPoints (SyncToken const & sync_token, NodeHandle const & node_handle, int32_t const point_indices[], size_t count);
431 
436  };
437 
440  public:
441  // Currently there are no config options.
442 
443  public:
444  bool operator== (OptimizeConfig const & other) const;
445  bool operator!= (OptimizeConfig const & other) const;
446  };
447 
448  OOC_API OptimizeResult OptimizeDeltas (SyncToken const & sync_token, OptimizeConfig const & config);
449 
457  friend SyncResult SynchronizeWith (Env, std::function<void(SyncToken const &)>);
458  friend ModifyResult DeleteNode (SyncToken const &, NodeHandle const &);
459  friend ModifyResult DeleteSpecificPoints (SyncToken const &, NodeHandle const &, int32_t const[], size_t);
460 
472  friend OptimizeResult OptimizeDeltas (SyncToken const & sync_token, OptimizeConfig const & config);
473 
474  public:
475  Env GetEnv () const;
476 
477  private:
478  SyncToken (Env env, PointCloudWorld & pcw);
479  PointCloudWorld & GetWorld () const;
480 
481  private:
482  SyncToken (SyncToken const &); // disable
483  SyncToken (SyncToken &&); // disable
484  void operator= (SyncToken const &); // disable
485  void operator= (SyncToken &&); // disable
486  void operator& () const; // disable
487 
488  private:
489  Env env;
490  PointCloudWorld & pcw;
491  };
492 
493 
494  // NOTE: Because std::function is in the API, this function must be defined in the header to avoid ABI problems.
495  inline OOC_API SyncResult SynchronizeWith (Env env, std::function<void(SyncToken const &)> func)
496  {
497  InternalSynchronizer synchronizer(env);
498  PointCloudWorld & pcw = synchronizer.GetWorld();
499  SyncToken const sync_token(env, pcw);
500  func(sync_token);
501  return SyncResult_Success;
502  }
503  }
504 
505 
506  namespace io
507  {
509  enum IOResult {
520  };
521 
538  OOC_API IOResult FileInputByKey (wchar_t const * file_name, HC_KEY segment_key, HInputHandlerOptions const & options);
539  OOC_API IOResult FileInputByKey (char * buffer, int buffer_size, wchar_t const * file_name, HC_KEY segment_key, HInputHandlerOptions const & options);
540 
569  OOC_API IOResult CommitDeltasToFile (Env env, H_UTF8 * out_generated_file_name = 0);
570  OOC_API IOResult CommitDeltasToFile (char * buffer, int buffer_size, Env env, H_UTF8 * out_generated_file_name = 0);
571 
575  OOC_API IOResult CommitDeltasToFile (Env env, H_UTF8 const & file_name);
576  OOC_API IOResult CommitDeltasToFile (char * buffer, int buffer_size, Env env, H_UTF8 const & file_name);
577 
587  OOC_API bool HasUncommittedDeltas (Env env);
588  }
589 
590 
591  namespace query
592  {
593  class QueryIterator;
594 
596  enum Storage {
599  };
600 
602  class OOC_API Filter {
603  friend class QueryIterator;
604 
605  public:
606  Filter () {}
607  virtual ~Filter () {}
608 
613  virtual bool RejectPointsInMemory () = 0;
614 
619  virtual bool RejectPointsOnDisk () = 0;
620 
626  virtual bool RejectNode (NodeHandle const & node_handle) = 0;
627 
634  virtual bool RejectBounding (Point const & min_bound, Point const & max_bound) = 0;
635 
641  virtual bool AcceptPoint (Point const & point, size_t point_index) = 0;
642  };
643 
647  friend class QueryIterator;
648 
649  private:
650  QueryResult ();
651 
652  public:
657  NodeHandle const & GetNodeHandle () const;
658 
663  RGBColor const & GetNodePointColor () const;
664 
669  Point const & GetNodePoint () const;
670 
675  size_t GetNodePointIndex () const;
676 
681  Storage GetStorage () const;
682 
683  private:
684  NodeHandle node_handle;
685  RGBColor node_point_color;
686  Point node_point;
687  size_t node_point_index;
688  Storage storage;
689  };
690 
698  OOC_API QueryIterator QueryPoints (Env env, Filter & filter);
699 
706  OOC_API int PointCount (Env env, NodeHandle const & handle);
707 
710  friend QueryIterator QueryPoints (Env, Filter &);
711 
712  public:
713  enum Status {
721  };
722 
723  private:
724  QueryIterator (Filter & filter, Status status);
725  QueryIterator (Env env, Filter & filter, NodeHandle const & node_handle);
726 
727  public:
731  QueryIterator ();
732 
736  QueryIterator (QueryIterator && other);
737  ~QueryIterator ();
738 
743  QueryResult const & operator* () const;
744 
749  QueryResult const * operator-> () const;
750 
755  Status GetStatus () const;
756 
759  void Advance ();
760 
761  private:
762  void InvalidateWith (Status status);
763 
764  enum HookStatus {
765  HookStatus_Success_Hooked,
766  HookStatus_Success_Skipped,
767  HookStatus_Error_Unknown_Failure,
768  HookStatus_Error_File_System_Failure,
769  HookStatus_Error_Deserialization_Failure,
770  HookStatus_Error_Corrupt_Node,
771  };
772 
773  void Hook ();
774  HookStatus HookNode (NodeHandle const & node_handle, HC_KEY const node_segment_key);
775  HookStatus HookNodePoints (HC_KEY const node_segment_key);
776  HookStatus HookNodePointsAgainstShell (HC_KEY const node_shell_key);
777  HookStatus HookNodePointsAgainstDisk (HC_KEY const node_segment_key);
778 
779  private:
780  QueryIterator (QueryIterator const &); // disable
781  void operator= (QueryIterator const &); // disable
782  void operator= (QueryIterator &&); // disable
783 
784  private:
785  void * typeless_pending_node_keys;
786  void * typeless_point_buffer;
787  void * typeless_color_buffer;
788  size_t point_buffer_idx;
789  Filter & filter;
790  Env const env;
791  QueryResult query_result;
792  Status status;
793  };
794  }
795 
796 
797  namespace preprocess
798  {
806  };
807 
808 
810  public:
811  Preprocessor (wchar_t const * output_file_name);
812  ~Preprocessor ();
813 
814  PreprocessStatus Run ();
815 
816  void SetLogFile (wchar_t const * log_file);
817  void AddPointCloudFile (wchar_t const * point_cloud_file);
818  void SetMaxShellSize (int shell_size);
819  void SetMaxMemoryUsage (size_t max_memory_usage);
820  void SetSubSamplePercentage (double percentage);
821  void SetCullingBoundingBox (Point const & min, Point const & max);
822  void OverwriteExistingFiles (bool overwrite);
823 
824  private:
825  void * opaque_point_cloud;
826  };
827  }
828 }
829 
830 
831 
832 
833 
834 
835 
836 
837 
838 
839 
840 
841 
842 
843 
Definition: PointCloudAPI.h:519
Definition: PointCloudAPI.h:392
Definition: PointCloudAPI.h:512
float r
Definition: PointCloudAPI.h:103
OOC_API bool GetEnv(HC_KEY ooc_root, Env &out_env)
OOC_API QueryIterator QueryPoints(Env env, Filter &filter)
float b
Definition: PointCloudAPI.h:105
Definition: PointCloudAPI.h:356
Definition: PointCloudAPI.h:510
PreprocessStatus
Definition: PointCloudAPI.h:799
OOC_API ModifyResult DeleteSpecificPoints(SyncToken const &sync_token, NodeHandle const &node_handle, int32_t const point_indices[], size_t count)
OOC_API int Configure(char const *in, char *out)
Definition: PointCloudAPI.h:375
OOC_API bool PollNodesLoadingOrHaveBeenLoaded(Env env)
Status
Definition: PointCloudAPI.h:713
float g
Definition: PointCloudAPI.h:104
Point(float x, float y, float z)
Definition: PointCloudAPI.h:125
virtual ~Filter()
Definition: PointCloudAPI.h:607
Definition: PointCloudAPI.h:800
OOC_API HC_KEY GetShellKey(Env env, NodeHandle const &node_handle)
#define HC_KEY
OOC_API bool IsRoot(HC_KEY ooc_root)
OOC_API ModifyResult DeleteNode(SyncToken const &sync_token, NodeHandle const &node_handle)
SyncResult
Definition: PointCloudAPI.h:355
OOC_API void Destroy(Env env)
float x
Definition: PointCloudAPI.h:168
Filter()
Definition: PointCloudAPI.h:606
Definition: PointCloudAPI.h:709
Definition: PointCloudAPI.h:393
Definition: PointCloudAPI.h:511
Definition: PointCloudAPI.h:81
OOC_API SyncResult SynchronizeWith(Env, std::function< void(SyncToken const &)>)
Definition: PointCloudAPI.h:495
Definition: PointCloudAPI.h:175
OOC_API HC_KEY GetRoot(Env env)
Definition: PointCloudAPI.h:598
Definition: PointCloudAPI.h:456
OptimizeResult
Definition: PointCloudAPI.h:433
Definition: PointCloudAPI.h:714
float z
Definition: PointCloudAPI.h:170
Definition: PointCloudAPI.h:646
Storage
Definition: PointCloudAPI.h:596
Definition: PointCloudAPI.h:439
OOC_API IOResult FileInputByKey(wchar_t const *file_name, HC_KEY segment_key, HInputHandlerOptions const &options)
Definition: PointCloudAPI.h:809
OOC_API OptimizeResult OptimizeDeltas(SyncToken const &sync_token, OptimizeConfig const &config)
NodeHandle()
Definition: PointCloudAPI.h:184
OOC_API HC_KEY GetSegmentKey(Env env, NodeHandle const &node_handle)
OOC_API bool GetNodeHandle(Env env, HC_KEY node_segment_key, NodeHandle &out_node_handle)
OOC_API void Release(Env env)
class OOC_API SyncToken
Definition: PointCloudAPI.h:352
Definition: PointCloudAPI.h:61
bool IsValid() const
Definition: PointCloudAPI.h:98
Definition: PointCloudAPI.h:597
Definition: PointCloudAPI.h:514
Point()
Definition: PointCloudAPI.h:113
float y
Definition: PointCloudAPI.h:169
Definition: PointCloudAPI.h:516
RGBColor()
Definition: PointCloudAPI.h:84
Definition: PointCloudAPI.h:715
IOResult
Definition: PointCloudAPI.h:509
Definition: PointCloudAPI.h:398
RGBColor(float r, float g, float b)
Definition: PointCloudAPI.h:91
Definition: PointCloudAPI.h:110
OOC_API IOResult CommitDeltasToFile(Env env, H_UTF8 *out_generated_file_name=0)
#define OOC_API
Definition: PointCloudAPI.h:27
OOC_API bool HasUncommittedDeltas(Env env)
Definition: PointCloudAPI.h:517
OOC_API int PointCount(Env env, NodeHandle const &handle)
Definition: PointCloudAPI.h:602
ModifyResult
Definition: PointCloudAPI.h:391
Definition: PointCloudAPI.h:434