Panda3D
 All Classes Functions Variables Enumerations
geomLines.cxx
1 // Filename: geomLines.cxx
2 // Created by: drose (22Mar05)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "geomLines.h"
16 #include "pStatTimer.h"
17 #include "bamReader.h"
18 #include "bamWriter.h"
19 #include "graphicsStateGuardianBase.h"
20 #include "geomVertexReader.h"
21 #include "geomVertexWriter.h"
22 
23 TypeHandle GeomLines::_type_handle;
24 
25 ////////////////////////////////////////////////////////////////////
26 // Function: GeomLines::Constructor
27 // Access: Published
28 // Description:
29 ////////////////////////////////////////////////////////////////////
30 GeomLines::
31 GeomLines(GeomLines::UsageHint usage_hint) :
32  GeomPrimitive(usage_hint)
33 {
34 }
35 
36 ////////////////////////////////////////////////////////////////////
37 // Function: GeomLines::Copy Constructor
38 // Access: Published
39 // Description:
40 ////////////////////////////////////////////////////////////////////
41 GeomLines::
42 GeomLines(const GeomLines &copy) :
43  GeomPrimitive(copy)
44 {
45 }
46 
47 ////////////////////////////////////////////////////////////////////
48 // Function: GeomLines::Destructor
49 // Access: Published, Virtual
50 // Description:
51 ////////////////////////////////////////////////////////////////////
52 GeomLines::
53 ~GeomLines() {
54 }
55 
56 ////////////////////////////////////////////////////////////////////
57 // Function: GeomLines::make_copy
58 // Access: Public, Virtual
59 // Description:
60 ////////////////////////////////////////////////////////////////////
62 make_copy() const {
63  return new GeomLines(*this);
64 }
65 
66 ////////////////////////////////////////////////////////////////////
67 // Function: GeomLines::get_primitive_type
68 // Access: Public, Virtual
69 // Description: Returns the fundamental rendering type of this
70 // primitive: whether it is points, lines, or polygons.
71 //
72 // This is used to set up the appropriate antialiasing
73 // settings when AntialiasAttrib::M_auto is in effect;
74 // it also implies the type of primitive that will be
75 // produced when decompose() is called.
76 ////////////////////////////////////////////////////////////////////
77 GeomPrimitive::PrimitiveType GeomLines::
78 get_primitive_type() const {
79  return PT_lines;
80 }
81 
82 ////////////////////////////////////////////////////////////////////
83 // Function: GeomLines::get_num_vertices_per_primitive
84 // Access: Public, Virtual
85 // Description: If the primitive type is a simple type in which all
86 // primitives have the same number of vertices, like
87 // lines, returns the number of vertices per
88 // primitive. If the primitive type is a more complex
89 // type in which different primitives might have
90 // different numbers of vertices, for instance a
91 // line strip, returns 0.
92 ////////////////////////////////////////////////////////////////////
93 int GeomLines::
95  return 2;
96 }
97 
98 ////////////////////////////////////////////////////////////////////
99 // Function: GeomLines::get_min_num_vertices_per_primitive
100 // Access: Public, Virtual
101 // Description: Returns the minimum number of vertices that must be
102 // added before close_primitive() may legally be called.
103 ////////////////////////////////////////////////////////////////////
104 int GeomLines::
106  return 2;
107 }
108 
109 ////////////////////////////////////////////////////////////////////
110 // Function: GeomLines::draw
111 // Access: Public, Virtual
112 // Description: Calls the appropriate method on the GSG to draw the
113 // primitive.
114 ////////////////////////////////////////////////////////////////////
115 bool GeomLines::
117  bool force) const {
118  return gsg->draw_lines(reader, force);
119 }
120 
121 ////////////////////////////////////////////////////////////////////
122 // Function: GeomLines::rotate_impl
123 // Access: Protected, Virtual
124 // Description: The virtual implementation of do_rotate().
125 ////////////////////////////////////////////////////////////////////
127 rotate_impl() const {
128  // To rotate lines, we just move reverse the pairs of vertices.
129  int num_vertices = get_num_vertices();
130 
131  PT(GeomVertexArrayData) new_vertices = make_index_data();
132  new_vertices->set_num_rows(num_vertices);
133 
134  if (is_indexed()) {
135  CPT(GeomVertexArrayData) vertices = get_vertices();
136  GeomVertexReader from(vertices, 0);
137  GeomVertexWriter to(new_vertices, 0);
138 
139  for (int begin = 0; begin < num_vertices; begin += 2) {
140  from.set_row_unsafe(begin + 1);
141  to.set_data1i(from.get_data1i());
142  from.set_row_unsafe(begin);
143  to.set_data1i(from.get_data1i());
144  }
145 
146  nassertr(to.is_at_end(), NULL);
147 
148  } else {
149  // Nonindexed case.
150  int first_vertex = get_first_vertex();
151  GeomVertexWriter to(new_vertices, 0);
152 
153  for (int begin = 0; begin < num_vertices; begin += 2) {
154  to.set_data1i(begin + 1 + first_vertex);
155  to.set_data1i(begin + first_vertex);
156  }
157 
158  nassertr(to.is_at_end(), NULL);
159  }
160 
161  return new_vertices;
162 }
163 
164 ////////////////////////////////////////////////////////////////////
165 // Function: GeomLines::register_with_read_factory
166 // Access: Public, Static
167 // Description: Tells the BamReader how to create objects of type
168 // Geom.
169 ////////////////////////////////////////////////////////////////////
170 void GeomLines::
172  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
173 }
174 
175 ////////////////////////////////////////////////////////////////////
176 // Function: GeomLines::make_from_bam
177 // Access: Protected, Static
178 // Description: This function is called by the BamReader's factory
179 // when a new object of type Geom is encountered
180 // in the Bam file. It should create the Geom
181 // and extract its information from the file.
182 ////////////////////////////////////////////////////////////////////
183 TypedWritable *GeomLines::
184 make_from_bam(const FactoryParams &params) {
185  GeomLines *object = new GeomLines(UH_unspecified);
186  DatagramIterator scan;
187  BamReader *manager;
188 
189  parse_params(params, scan, manager);
190  object->fillin(scan, manager);
191 
192  return object;
193 }
This object provides a high-level interface for quickly writing a sequence of numeric values from a v...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
This is an abstract base class for a family of classes that represent the fundamental geometry primit...
Definition: geomPrimitive.h:63
void set_data1i(int data)
Sets the write row to a particular 1-component value, and advances the write row. ...
virtual bool draw(GraphicsStateGuardianBase *gsg, const GeomPrimitivePipelineReader *reader, bool force) const
Calls the appropriate method on the GSG to draw the primitive.
Definition: geomLines.cxx:116
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
void register_factory(TypeHandle handle, CreateFunc *func)
Registers a new kind of thing the Factory will be able to create.
Definition: factory.I:90
Defines a series of disconnected line segments.
Definition: geomLines.h:25
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:213
virtual int get_num_vertices_per_primitive() const
If the primitive type is a simple type in which all primitives have the same number of vertices...
Definition: geomLines.cxx:94
This object provides a high-level interface for quickly reading a sequence of numeric values from a v...
static void register_with_read_factory()
Tells the BamReader how to create objects of type Geom.
Definition: geomLines.cxx:171
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:85
virtual int get_min_num_vertices_per_primitive() const
Returns the minimum number of vertices that must be added before close_primitive() may legally be cal...
Definition: geomLines.cxx:105
Encapsulates the data from a GeomPrimitive, pre-fetched for one stage of the pipeline.
This is the data for one array of a GeomVertexData structure.
bool is_at_end() const
Returns true if the writer is currently at the end of the list of vertices, false otherwise...