Panda3D
clipPlaneAttrib.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file clipPlaneAttrib.h
10  * @author drose
11  * @date 2002-07-11
12  */
13 
14 #ifndef CLIPPINGPLANEATTRIB_H
15 #define CLIPPINGPLANEATTRIB_H
16 
17 #include "pandabase.h"
18 
19 #include "planeNode.h"
20 #include "renderAttrib.h"
21 #include "nodePath.h"
22 #include "ordered_vector.h"
23 #include "pmap.h"
24 
25 /**
26  * This functions similarly to a LightAttrib. It indicates the set of
27  * clipping planes that modify the geometry at this level and below. A
28  * ClipPlaneAttrib can either add planes or remove planes from the total set
29  * of clipping planes in effect.
30  */
31 class EXPCL_PANDA_PGRAPH ClipPlaneAttrib : public RenderAttrib {
32 private:
33  INLINE ClipPlaneAttrib();
34  INLINE ClipPlaneAttrib(const ClipPlaneAttrib &copy);
35 
36 PUBLISHED:
37 
38  // This is the old, deprecated interface to ClipPlaneAttrib. Do not use any
39  // of these methods for new code; these methods will be removed soon.
40  enum Operation {
41  O_set,
42  O_add,
43  O_remove
44  };
45 
46  static CPT(RenderAttrib) make(Operation op,
47  PlaneNode *plane);
48  static CPT(RenderAttrib) make(Operation op,
49  PlaneNode *plane1, PlaneNode *plane2);
50  static CPT(RenderAttrib) make(Operation op,
51  PlaneNode *plane1, PlaneNode *plane2,
52  PlaneNode *plane3);
53  static CPT(RenderAttrib) make(Operation op,
54  PlaneNode *plane1, PlaneNode *plane2,
55  PlaneNode *plane3, PlaneNode *plane4);
56  static CPT(RenderAttrib) make_default();
57 
58  Operation get_operation() const;
59 
60  int get_num_planes() const;
61  PlaneNode *get_plane(int n) const;
62  bool has_plane(PlaneNode *plane) const;
63 
64  CPT(RenderAttrib) add_plane(PlaneNode *plane) const;
65  CPT(RenderAttrib) remove_plane(PlaneNode *plane) const;
66 
67 
68  // The following is the new, more general interface to the ClipPlaneAttrib.
69  static CPT(RenderAttrib) make();
70  static CPT(RenderAttrib) make_all_off();
71 
72  INLINE int get_num_on_planes() const;
73  INLINE NodePath get_on_plane(int n) const;
74  MAKE_SEQ(get_on_planes, get_num_on_planes, get_on_plane);
75  INLINE bool has_on_plane(const NodePath &plane) const;
76 
77  INLINE int get_num_off_planes() const;
78  INLINE NodePath get_off_plane(int n) const;
79  MAKE_SEQ(get_off_planes, get_num_off_planes, get_off_plane);
80  INLINE bool has_off_plane(const NodePath &plane) const;
81  INLINE bool has_all_off() const;
82 
83  INLINE bool is_identity() const;
84 
85  CPT(RenderAttrib) add_on_plane(const NodePath &plane) const;
86  CPT(RenderAttrib) remove_on_plane(const NodePath &plane) const;
87  CPT(RenderAttrib) add_off_plane(const NodePath &plane) const;
88  CPT(RenderAttrib) remove_off_plane(const NodePath &plane) const;
89 
90  CPT(ClipPlaneAttrib) filter_to_max(int max_clip_planes) const;
91 
92 public:
93  CPT(RenderAttrib) compose_off(const RenderAttrib *other) const;
94  virtual void output(std::ostream &out) const;
95 
96 protected:
97  virtual int compare_to_impl(const RenderAttrib *other) const;
98  virtual size_t get_hash_impl() const;
99  virtual CPT(RenderAttrib) compose_impl(const RenderAttrib *other) const;
100  virtual CPT(RenderAttrib) invert_compose_impl(const RenderAttrib *other) const;
101 
102 private:
103  INLINE void check_filtered() const;
104  void sort_on_planes();
105 
106 private:
107  typedef ov_set<NodePath> Planes;
108  Planes _on_planes, _off_planes;
109  bool _off_all_planes;
110 
111  typedef pmap< int, CPT(ClipPlaneAttrib) > Filtered;
112  Filtered _filtered;
113 
114  UpdateSeq _sort_seq;
115 
116  static CPT(RenderAttrib) _empty_attrib;
117  static CPT(RenderAttrib) _all_off_attrib;
118 
119 PUBLISHED:
120  static int get_class_slot() {
121  return _attrib_slot;
122  }
123  virtual int get_slot() const {
124  return get_class_slot();
125  }
126  MAKE_PROPERTY(class_slot, get_class_slot);
127 
128 public:
129  // This data is only needed when reading from a bam file.
130  typedef pvector<PT(PandaNode) > NodeList;
132  public:
133  // We hold a pointer to each of the PandaNodes on the on_list and
134  // off_list. We will later convert these to NodePaths in
135  // finalize().
136  int _num_off_planes;
137  int _num_on_planes;
138  NodeList _off_list;
139  NodeList _on_list;
140  };
141 
142 public:
143  static void register_with_read_factory();
144  virtual void write_datagram(BamWriter *manager, Datagram &dg);
145  virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
146 
147  virtual void finalize(BamReader *manager);
148 
149 protected:
150  static TypedWritable *make_from_bam(const FactoryParams &params);
151  void fillin(DatagramIterator &scan, BamReader *manager);
152 
153 public:
154  static TypeHandle get_class_type() {
155  return _type_handle;
156  }
157  static void init_type() {
158  RenderAttrib::init_type();
159  register_type(_type_handle, "ClipPlaneAttrib",
160  RenderAttrib::get_class_type());
161  _attrib_slot = register_slot(_type_handle, 100, new ClipPlaneAttrib);
162  }
163  virtual TypeHandle get_type() const {
164  return get_class_type();
165  }
166  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
167 
168 private:
169  static TypeHandle _type_handle;
170  static int _attrib_slot;
171 };
172 
173 #include "clipPlaneAttrib.I"
174 
175 #endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A basic node of the scene graph or data graph.
Definition: pandaNode.h:64
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is our own Panda specialization on the default STL map.
Definition: pmap.h:49
This is the base class for a number of render attributes (other than transform) that may be set on sc...
Definition: renderAttrib.h:51
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This functions similarly to a LightAttrib.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
This is our own Panda specialization on the default STL list.
Definition: plist.h:35
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:42
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
static int register_slot(TypeHandle type_handle, int sort, RenderAttrib *default_attrib)
Adds the indicated TypeHandle to the registry, if it is not there already, and returns a unique slot ...
Definition: renderAttrib.I:101
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
virtual void finalize(BamReader *manager)
Called by the BamReader to perform any final actions needed for setting up the object after all objec...
A class to retrieve the individual data elements previously stored in a Datagram.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
This is a sequence number that increments monotonically.
Definition: updateSeq.h:37
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:161
A node that contains a plane.
Definition: planeNode.h:36