00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef ARCHON_X3D_GEOMETRY_H
00021 #define ARCHON_X3D_GEOMETRY_H
00022
00029 #include <archon/x3d/server/geoprop.H>
00030 #include <archon/x3d/server/texture.H>
00031 #include <archon/x3d/server/appear.H>
00032
00033 namespace Archon
00034 {
00035 namespace X3D
00036 {
00037 struct RenderConfig
00038 {
00043 int subdivision1;
00044
00049 int subdivision2;
00050
00051 bool showNormals;
00052
00053 Vector3 normalColor;
00054 double normalLength;
00055
00056 bool wireframeMode;
00057 bool textAsQuadsMode;
00058
00059 RenderConfig(int subdivision1,
00060 int subdivision2,
00061 bool showNormals,
00062 double normalLength,
00063 bool wireframeMode,
00064 bool textAsQuadsMode):
00065 subdivision1(subdivision1),
00066 subdivision2(subdivision2),
00067 showNormals(showNormals),
00068 normalColor(1, 0, 0),
00069 normalLength(normalLength),
00070 wireframeMode(wireframeMode),
00071 textAsQuadsMode(textAsQuadsMode) {}
00072 };
00073
00074 struct Shape;
00075
00079 struct GeometryNode: virtual Node
00080 {
00081 static const NodeType *type;
00082
00109 virtual int intersect(const Math::Ray3 &, double &dist) const = 0;
00110
00128 virtual void getNormalAndTexCoord(Vector3 hitPoint, int where,
00129 const Shape *,
00130 Vector3 *hitNormal,
00131 Vector2 *hitTexCoord) const = 0;
00132
00154 virtual void render(bool texture,
00155 const Shape *shape,
00156 const RenderConfig *) = 0;
00157
00158 protected:
00159 GeometryNode() {}
00160 };
00161
00162
00166 struct Geometry3DNode: GeometryNode
00167 {
00168 static const NodeType *type;
00169
00170 protected:
00171 Geometry3DNode() {}
00172 };
00173
00174
00197 struct Box: Geometry3DNode
00198 {
00199 static Ref<NodeBase> instantiate(BackRef<ExecutionContext> c)
00200 {
00201 return new Box(c);
00202 }
00203
00204 static const NodeType *type;
00205 const NodeType *getType() const { return type; }
00206
00207 Box(BackRef<ExecutionContext> c): NodeBase(c), size(2, 2, 2) {}
00208
00209 const Vector3 &getSize() const { return size; }
00210
00211 int intersect(const Math::Ray3 &, double &dist) const;
00212
00213 void getNormalAndTexCoord(Vector3 hitPoint, int where,
00214 const Shape *,
00215 Vector3 *hitNormal,
00216 Vector2 *hitTexCoord) const;
00217
00218 void render(bool texture,
00219 const Shape *shape,
00220 const RenderConfig *);
00221
00222 private:
00223 friend void initializeGeometryComponent();
00224
00225 Vector3 size;
00226 };
00227
00228
00253 struct Cone: Geometry3DNode
00254 {
00255 static Ref<NodeBase> instantiate(BackRef<ExecutionContext> c)
00256 {
00257 return new Cone(c);
00258 }
00259
00260 static const NodeType *type;
00261 const NodeType *getType() const { return type; }
00262
00263 Cone(BackRef<ExecutionContext> c):
00264 NodeBase(c), bottomRadius(1),
00265 height(2), side(true), bottom(true) {}
00266
00267 double getBottomRadius() const { return bottomRadius; }
00268 double getHeight() const { return height; }
00269 bool getSide() const { return side; }
00270 bool getBottom() const { return bottom; }
00271
00272 int intersect(const Math::Ray3 &, double &dist) const;
00273
00274 void getNormalAndTexCoord(Vector3 hitPoint, int where,
00275 const Shape *,
00276 Vector3 *hitNormal,
00277 Vector2 *hitTexCoord) const;
00278
00279 void render(bool texture,
00280 const Shape *shape,
00281 const RenderConfig *);
00282
00283 private:
00284 friend void initializeGeometryComponent();
00285
00286 double bottomRadius;
00287 double height;
00288 bool side;
00289 bool bottom;
00290 };
00291
00292
00314 struct Cylinder: Geometry3DNode
00315 {
00316 static Ref<NodeBase> instantiate(BackRef<ExecutionContext> c)
00317 {
00318 return new Cylinder(c);
00319 }
00320
00321 static const NodeType *type;
00322 const NodeType *getType() const { return type; }
00323
00324 Cylinder(BackRef<ExecutionContext> c):
00325 NodeBase(c), height(2), radius(1),
00326 side(true), top(true), bottom(true) {}
00327
00328 double getHeight() const { return height; }
00329 double getRadius() const { return radius; }
00330 bool getSide() const { return side; }
00331 bool getTop() const { return top; }
00332 bool getBottom() const { return bottom; }
00333
00334 int intersect(const Math::Ray3 &, double &dist) const;
00335
00336 void getNormalAndTexCoord(Vector3 hitPoint, int where,
00337 const Shape *,
00338 Vector3 *hitNormal,
00339 Vector2 *hitTexCoord) const;
00340
00341 void render(bool texture,
00342 const Shape *shape,
00343 const RenderConfig *);
00344
00345 private:
00346 friend void initializeGeometryComponent();
00347
00348 double height;
00349 double radius;
00350 bool side;
00351 bool top;
00352 bool bottom;
00353 };
00354
00355
00359 struct IndexedLineSet: Geometry3DNode
00360 {
00361 static Ref<NodeBase> instantiate(BackRef<ExecutionContext> c)
00362 {
00363 return new IndexedLineSet(c);
00364 }
00365
00366 static const NodeType *type;
00367 const NodeType *getType() const { return type; }
00368
00369 IndexedLineSet(BackRef<ExecutionContext> c):
00370 NodeBase(c), colorPerVertex(true), lineWidth(1) {}
00371
00372 Ref<ColorNode> getColor() const { return color; }
00373 Ref<CoordinateNode> getCoord() const { return coord; }
00374 vector<int> getColorIndex() const { return colorIndex; }
00375 bool getColorPerVertex() const { return colorPerVertex; }
00376 vector<int> getCoordIndex() const { return coordIndex; }
00377 double getLineWidth() const { return lineWidth; }
00378
00379 int intersect(const Math::Ray3 &, double &dist) const { return 0; }
00380 void getNormalAndTexCoord(Vector3, int, const Shape *,
00381 Vector3 *, Vector2 *) const {};
00382
00383 void render(bool texture,
00384 const Shape *shape,
00385 const RenderConfig *);
00386
00387 private:
00388 friend void initializeGeometryComponent();
00389
00390 Ref<ColorNode> color;
00391 Ref<CoordinateNode> coord;
00392 vector<int> colorIndex;
00393 bool colorPerVertex;
00394 vector<int> coordIndex;
00395 double lineWidth;
00396
00397 EventSource colorChanged;
00398 EventSource coordChanged;
00399
00400 Time colorStamp;
00401 Time coordStamp;
00402 Time colorIndexStamp;
00403 Time coordIndexStamp;
00404 };
00405
00409 struct PointSet: Geometry3DNode
00410 {
00411 static Ref<NodeBase> instantiate(BackRef<ExecutionContext> c)
00412 {
00413 return new PointSet(c);
00414 }
00415
00416 static const NodeType *type;
00417 const NodeType *getType() const { return type; }
00418
00419 PointSet(BackRef<ExecutionContext> c): NodeBase(c) {}
00420
00421 Ref<ColorNode> getColor() const { return color; }
00422 Ref<CoordinateNode> getCoord() const { return coord; }
00423
00424 int intersect(const Math::Ray3 &, double &dist) const { return 0; }
00425 void getNormalAndTexCoord(Vector3, int, const Shape *,
00426 Vector3 *, Vector2 *) const {};
00427
00428 void render(bool texture,
00429 const Shape *shape,
00430 const RenderConfig *);
00431
00432 private:
00433 friend void initializeGeometryComponent();
00434
00435 Ref<ColorNode> color;
00436 Ref<CoordinateNode> coord;
00437
00438 EventSource colorChanged;
00439 EventSource coordChanged;
00440
00441 Time colorStamp;
00442 Time coordStamp;
00443 };
00444
00445
00464 struct Sphere: Geometry3DNode
00465 {
00466 static Ref<NodeBase> instantiate(BackRef<ExecutionContext> c)
00467 {
00468 return new Sphere(c);
00469 }
00470
00471 static const NodeType *type;
00472 const NodeType *getType() const { return type; }
00473
00474 Sphere(BackRef<ExecutionContext> c): NodeBase(c), radius(1) {}
00475
00476 double getRadius() const { return radius; }
00477
00478 int intersect(const Math::Ray3 &, double &dist) const;
00479
00480 void getNormalAndTexCoord(Vector3 hitPoint, int where,
00481 const Shape *,
00482 Vector3 *hitNormal,
00483 Vector2 *hitTexCoord) const;
00484
00485 void render(bool texture,
00486 const Shape *shape,
00487 const RenderConfig *);
00488
00489 private:
00490 friend void initializeGeometryComponent();
00491
00492 double radius;
00493 };
00494
00498 struct ComposedGeometryNode: Geometry3DNode
00499 {
00500 static const NodeType *type;
00501
00502 bool getCCW() const { return ccw; }
00503 bool getColorPerVertex() const { return colorPerVertex; }
00504 bool getNormalPerVertex() const { return normalPerVertex; }
00505 bool getSolid() const { return solid; }
00506
00507 Ref<const CoordinateNode> getCoord() const { return coord; }
00508 Ref< CoordinateNode> getCoord() { return coord; }
00509 Ref<const ColorNode> getColor() const { return color; }
00510 Ref< ColorNode> getColor() { return color; }
00511 Ref<const NormalNode> getNormal() const { return normal; }
00512 Ref< NormalNode> getNormal() { return normal; }
00513 Ref<const TextureCoordinateNode> getTexCoord() const { return texCoord; }
00514 Ref< TextureCoordinateNode> getTexCoord() { return texCoord; }
00515
00516 protected:
00517 ComposedGeometryNode():
00518 ccw(true),
00519 colorPerVertex(true),
00520 normalPerVertex(true),
00521 solid(true) {}
00522
00523 friend class Viewer;
00524 friend void initializeGeometryComponent();
00525
00526 bool ccw;
00527 bool colorPerVertex;
00528 bool normalPerVertex;
00529 bool solid;
00530
00531 Ref<CoordinateNode> coord;
00532 Ref<ColorNode> color;
00533 Ref<NormalNode> normal;
00534 Ref<TextureCoordinateNode> texCoord;
00535
00536 bool coordAssign(const Ref<CoordinateNode> &, const Time &);
00537 bool colorAssign(const Ref<ColorNode> &, const Time &);
00538 bool normalAssign(const Ref<NormalNode> &, const Time &);
00539 bool texCoordAssign(const Ref<TextureCoordinateNode> &, const Time &);
00540
00541 EventSource colorChanged;
00542 EventSource coordChanged;
00543 EventSource normalChanged;
00544 EventSource texCoordChanged;
00545
00546 Time colorStamp;
00547 Time coordStamp;
00548 Time normalStamp;
00549 Time texCoordStamp;
00550
00551 virtual void reprocess() {};
00552 };
00553
00554
00558 struct ElevationGrid: ComposedGeometryNode
00559 {
00560 static Ref<NodeBase> instantiate(BackRef<ExecutionContext> c)
00561 {
00562 return new ElevationGrid(c);
00563 }
00564
00565 static const NodeType *type;
00566 const NodeType *getType() const { return type; }
00567
00568 ElevationGrid(BackRef<ExecutionContext> c):
00569 NodeBase(c), creaseAngle(0),
00570 xDimension(0), xSpacing(1), zDimension(0), zSpacing(1) {}
00571
00572 double getCreaseAngle() const { return creaseAngle; }
00573 const vector<double> &getHeight() const { return height; }
00574 int getXDimension() const { return xDimension; }
00575 double getXSpacing() const { return xSpacing; }
00576 int getZDimension() const { return zDimension; }
00577 double getZSpacing() const { return zSpacing; }
00578
00579 int intersect(const Math::Ray3 &, double &dist) const;
00580
00581 void getNormalAndTexCoord(Vector3 hitPoint, int where,
00582 const Shape *,
00583 Vector3 *hitNormal,
00584 Vector2 *hitTexCoord) const;
00585
00586 void render(bool texture,
00587 const Shape *shape,
00588 const RenderConfig *);
00589
00590 private:
00591 friend void initializeGeometryComponent();
00592
00593 double creaseAngle;
00594 vector<double> height;
00595 int xDimension;
00596 double xSpacing;
00597 int zDimension;
00598 double zSpacing;
00599
00600 Time heightStamp;
00601 };
00602
00603
00607 struct IndexedFaceSet: ComposedGeometryNode
00608 {
00609 static Ref<NodeBase> instantiate(BackRef<ExecutionContext> c)
00610 {
00611 return new IndexedFaceSet(c);
00612 }
00613
00614 static const NodeType *type;
00615 const NodeType *getType() const { return type; }
00616
00617 IndexedFaceSet(BackRef<ExecutionContext> c):
00618 NodeBase(c), convex(true), creaseAngle(0), preprocessed(false) {}
00619
00620 bool getConvex() const { return convex; }
00621 double getCreaseAngle() const { return creaseAngle; }
00622
00623
00624
00625 const vector<int> &getCoordIndex() const { return coordIndex; }
00626
00627 const vector<int> &getColorIndex() const { return colorIndex; }
00628
00629 const vector<int> &getNormalIndex() const { return normalIndex; }
00630
00631 const vector<int> &getTexCoordIndex() const { return texCoordIndex; }
00632
00633 int intersect(const Math::Ray3 &, double &dist) const;
00634
00635 void getNormalAndTexCoord(Vector3 hitPoint, int where,
00636 const Shape *,
00637 Vector3 *hitNormal,
00638 Vector2 *hitTexCoord) const;
00639
00640 void render(bool texture,
00641 const Shape *shape,
00642 const RenderConfig *);
00643
00644 private:
00645 friend void initializeGeometryComponent();
00646
00647 bool convex;
00648 double creaseAngle;
00649
00650 vector<int> coordIndex;
00651 vector<int> colorIndex;
00652 vector<int> normalIndex;
00653 vector<int> texCoordIndex;
00654
00655 bool coordIndexAssign(const vector<int> &, const Time &);
00656 bool colorIndexAssign(const vector<int> &, const Time &);
00657 bool normalIndexAssign(const vector<int> &, const Time &);
00658 bool texCoordIndexAssign(const vector<int> &, const Time &);
00659
00660 Time colorIndexStamp;
00661 Time coordIndexStamp;
00662 Time normalIndexStamp;
00663 Time texCoordIndexStamp;
00664
00668 void reprocess();
00669
00678 void preprocess();
00679
00680 bool preprocessed;
00681 const vector<Vector3> *coords;
00682 const vector<Vector3> *rgbColors;
00683 const vector<Vector4> *rgbaColors;
00684 const vector<Vector3> *normals;
00685 const vector<Vector2> *texCoords;
00686 vector<int> preprocessedCoordIndex;
00687 vector<int> preprocessedColorIndex;
00688 vector<int> preprocessedNormalIndex;
00689 vector<int> preprocessedTexCoordIndex;
00690 vector<Vector3> preprocessedNormal;
00691 Vector3 preprocessedBboxCenter;
00692 Vector3 preprocessedBboxSize;
00693 };
00694
00695
00699 struct ShapeNode: virtual ChildNode
00700 {
00701 static const NodeType *type;
00702
00703 protected:
00704 ShapeNode() {}
00705 };
00706
00707
00711 struct Shape: ShapeNode, BoundedObject
00712 {
00713 static Ref<NodeBase> instantiate(BackRef<ExecutionContext> c)
00714 {
00715 return new Shape(c);
00716 }
00717
00718 static const NodeType *type;
00719 const NodeType *getType() const { return type; }
00720
00721 Shape(BackRef<ExecutionContext> c): NodeBase(c), drawCache(0) {}
00722
00723 Ref<const AppearanceNode> getAppearance() const { return appearance; }
00724 Ref< AppearanceNode> getAppearance() { return appearance; }
00725 Ref<const GeometryNode> getGeometry() const { return geometry; }
00726 Ref< GeometryNode> getGeometry() { return geometry; }
00727
00728 struct DrawCache
00729 {
00733 virtual ~DrawCache() {}
00734
00739 virtual void dispose() = 0;
00740 };
00741
00742 DrawCache *drawCache;
00743
00744 virtual ~Shape()
00745 {{
00746 if(drawCache) drawCache->dispose();
00747 }}
00748
00749 private:
00750 friend void initializeGeometryComponent();
00751
00752 Ref<AppearanceNode> appearance;
00753 Ref<GeometryNode> geometry;
00754
00755 EventSource appearanceChanged;
00756 EventSource geometryChanged;
00757
00758 Time appearanceStamp;
00759 Time geometryStamp;
00760 };
00761 }
00762 }
00763
00764 #endif // ARCHON_X3D_GEOMETRY_H