source: GTP/trunk/Lib/Vis/Preprocessing/src/mixkit/MxLineModel.h @ 1097

Revision 1097, 2.4 KB checked in by mattausch, 18 years ago (diff)
Line 
1#ifndef MXLINEMODEL_INCLUDED // -*- C++ -*-
2#define MXLINEMODEL_INCLUDED
3#if !defined(__GNUC__)
4#  pragma once
5#endif
6
7/************************************************************************
8
9  MxLineModel
10
11  Copyright (C) 1998 Michael Garland.  See "COPYING.txt" for details.
12 
13  $Id: MxLineModel.h,v 1.1 2002/09/24 16:53:54 wimmer Exp $
14
15 ************************************************************************/
16
17#include "MxDynBlock.h"
18#include "MxGeoPrims.h"
19
20typedef MxFaceID MxSegmentID;
21
22class MxVertex2D : public MxEQ
23{
24public:
25    float pos[2];
26
27    MxVertex2D() { }
28    MxVertex2D(float x, float y) { pos[0]=x; pos[1]=y; }
29    MxVertex2D(const MxVertex2D& v) { *this = v; }
30
31    MxVertex2D& operator=(const MxVertex2D& v)
32        { pos[0]=v.pos[0]; pos[1]=v.pos[1]; return *this; }
33
34    operator const float*() const { return pos; }
35    operator       float*()       { return pos; }
36#ifdef __GNUC__
37    float& operator[](int i)       { return pos[i]; }
38    float  operator[](int i) const { return pos[i]; }
39#endif
40};
41
42class MxSegment2D : public MxEQ
43{
44public:
45    MxVertexID v[2];
46
47    MxSegment2D() { }
48    MxSegment2D(MxVertexID v0, MxVertexID v1) { v[0]=v0; v[1]=v1; }
49    MxSegment2D(const MxSegment2D& s) { *this = s; }
50
51    MxSegment2D& operator=(const MxSegment2D& s)
52        { v[0]=s.v[0]; v[1]=s.v[1]; return *this; }
53
54    MxVertexID& operator[](int i)       { return v[i]; }
55    MxVertexID  operator[](int i) const { return v[i]; }
56};
57
58inline ostream& operator<<(ostream& out, const MxVertex2D& v)
59{
60    return out << "v " << v[0] << " " << v[1];
61}
62
63inline ostream& operator<<(ostream& out, const MxSegment2D& s)
64{
65    return out << "l " << s[0]+1 << " " << s[1]+1;
66}
67
68
69class MxLineModel
70{
71private:
72    MxDynBlock<MxVertex2D> vertices;
73    MxDynBlock<MxSegment2D> segments;
74
75
76public:
77    MxLineModel(uint nvert, uint nseg) : vertices(nvert), segments(nseg)
78        { }
79
80    uint vert_count() const { return vertices.length(); }
81    uint segment_count() const { return segments.length(); }
82
83    MxVertex2D&       vertex(uint i)       { return vertices(i); }
84    const MxVertex2D& vertex(uint i) const { return vertices(i); }
85    MxSegment2D&       segment(uint i)       { return segments(i); }
86    const MxSegment2D& segment(uint i) const { return segments(i); }
87
88    MxVertexID add_vertex(float, float);
89    MxFaceID add_segment(MxVertexID, MxVertexID);
90};
91
92
93
94
95// MXLINEMODEL_INCLUDED
96#endif
Note: See TracBrowser for help on using the repository browser.