source: trunk/packages/vizservers/nanovis/ConvexPolygon.h @ 2849

Last change on this file since 2849 was 2822, checked in by ldelgass, 12 years ago

Const correctness fixes, pass vector/matrix objects by reference, various
formatting and style cleanups, don't spam syslog and uncomment openlog() call.
Still needs to be compiled with -DWANT_TRACE to get tracing, but now trace
output will be output to file in /tmp.

  • Property svn:eol-style set to native
File size: 1.9 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * ----------------------------------------------------------------------
4 * ConvexPolygon.h: convex polygon class
5 *
6 * ======================================================================
7 *  AUTHOR:  Wei Qiao <qiaow@purdue.edu>
8 *           Purdue Rendering and Perceptualization Lab (PURPL)
9 *
10 *  Copyright (c) 2004-2006  Purdue Research Foundation
11 *
12 *  See the file "license.terms" for information on usage and
13 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14 * ======================================================================
15 */
16#ifndef _CONVEX_POLYGON_H_
17#define _CONVEX_POLYGON_H_
18
19#include <assert.h>
20#include <vector>
21
22#include "Vector4.h"
23#include "Plane.h"
24
25typedef std::vector<Vector4> VertexVector;
26typedef std::vector<Vector4> TexVector;
27
28class ConvexPolygon
29{
30public:
31    VertexVector vertices;
32    TexVector texcoords;
33    int volume_id;      //which volume this polygon slice belongs to
34
35    ConvexPolygon()
36    {}
37
38    ConvexPolygon(VertexVector vertices);
39
40    void transform(const Mat4x4& mat);
41
42    void translate(const Vector4& shift);
43
44    // Clips the polygon, retaining the portion where ax + by + cz + d >= 0
45    void clip(Plane& clipPlane, bool copy_to_texcoords);
46
47    void Emit(bool use_texture);
48
49    void Emit(bool use_texture, const Vector3& shift, const Vector3& scale);
50
51    void copy_vertices_to_texcoords();
52
53    void set_id(int v_id)
54    {
55        volume_id = v_id;
56    }
57
58    void append_vertex(const Vector4& vert)
59    {
60        vertices.push_back(vert);
61    }
62
63    void insert_vertex(unsigned int index, const Vector4& vert)
64    {
65        assert(index<vertices.size());
66        vertices.insert(vertices.begin() + index, vert);
67    }
68
69    bool is_retained(const Vector4& point, const Vector4& plane)
70    {
71        return ((point * plane) >= 0); 
72    }
73};
74
75#endif
Note: See TracBrowser for help on using the repository browser.