00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <UT/UT_DSOVersion.h>
00029
00030 #include <RE/RE_Render.h>
00031
00032 #include <GEO/GEO_Primitive.h>
00033
00034 #include <GU/GU_Detail.h>
00035 #include <GU/GU_PrimGroupClosure.h>
00036
00037 #include <GR/GR_Detail.h>
00038 #include <GR/GR_RenderHook.h>
00039 #include <GR/GR_RenderTable.h>
00040 #include <GR/GR_DisplayOption.h>
00041
00042 #include "EUC_Expression.h"
00043 #include "EUC_Object.h"
00044
00045 using namespace HDK_Sample;
00046
00047 namespace HDK_Sample {
00048
00049 class GR_Euclid : public GR_RenderHook
00050 {
00051 public:
00052 GR_Euclid() {}
00053 virtual ~GR_Euclid() {}
00054
00055
00056 static EUC_Expression *getExpression(const GU_Detail *gdp);
00057
00058 int getWireMask(GU_Detail *gdp,
00059 const GR_DisplayOption * ) const
00060 {
00061
00062 if (getExpression(gdp))
00063 return 0;
00064 else
00065 return GEOPRIMALL;
00066 }
00067
00068 void drawObject(EUC_Object *obj,
00069 RE_Render &ren,
00070 const GR_DisplayOption *dopt) const;
00071
00072 virtual void renderWire(GU_Detail *gdp,
00073 RE_Render &ren,
00074 const GR_AttribOffset &ptinfo,
00075 const GR_DisplayOption *dopt,
00076 float lod,
00077 const GU_PrimGroupClosure *hidden_geometry);
00078
00079 int getShadedMask(GU_Detail *gdp,
00080 const GR_DisplayOption * ) const
00081 {
00082
00083 if (getExpression(gdp))
00084 return 0;
00085 else
00086 return GEOPRIMALL;
00087 }
00088
00089 virtual void renderShaded(GU_Detail *gdp,
00090 RE_Render &ren,
00091 const GR_AttribOffset &ptinfo,
00092 const GR_DisplayOption *dopt,
00093 float lod,
00094 const GU_PrimGroupClosure *hidden_geometry);
00095
00096 virtual const char *getName() const { return "GR_Euclid"; }
00097 };
00098
00099 }
00100
00101 EUC_Expression *
00102 GR_Euclid::getExpression(const GU_Detail *gdp)
00103 {
00104 int aoff, euc;
00105 EUC_Expression *expr;
00106
00107 aoff = gdp->attribs().getOffset("euclid", GB_ATTRIB_INT);
00108 if (aoff < 0)
00109 return 0;
00110
00111 euc = *(gdp->attribs().castAttribData<int>(aoff));
00112 expr = EUC_Expression::getExprFromUid(euc);
00113 return expr;
00114 }
00115
00116 void
00117 GR_Euclid::renderWire(GU_Detail *gdp,
00118 RE_Render &ren,
00119 const GR_AttribOffset & ,
00120 const GR_DisplayOption *dopt,
00121 float ,
00122 const GU_PrimGroupClosure * )
00123 {
00124 EUC_Expression *expr;
00125
00126 expr = getExpression(gdp);
00127 if (!expr)
00128 return;
00129
00130
00131 EUC_ObjectList objlist;
00132 int i, n;
00133
00134 expr->evaluate(objlist);
00135
00136
00137 n = objlist.entries();
00138 for (i = 0; i < n; i++)
00139 {
00140 drawObject(objlist(i), ren, dopt);
00141 }
00142 }
00143
00144 void
00145 GR_Euclid::drawObject(EUC_Object *obj,
00146 RE_Render &ren,
00147 const GR_DisplayOption * ) const
00148 {
00149 if (!obj)
00150 return;
00151
00152 UT_Vector3 cd;
00153 UT_Color col;
00154
00155 if (!obj->getVisible())
00156 return;
00157
00158 cd = obj->getColor();
00159 col.setRGB(cd.x(), cd.y(), cd.z());
00160
00161 ren.pushColor(col);
00162 switch (obj->getType())
00163 {
00164 case EUC_PointType:
00165 {
00166 UT_Vector2 p;
00167
00168 ren.setFont(ren.getViewportSymbolFont(RE_SYMBOL_FONT_SIZE_SMALL));
00169
00170 p = ((EUC_Point *)obj)->getPos();
00171
00172 ren.textMove3W(p.x(), p.y(), 0);
00173 ren.putChar(10);
00174
00175 break;
00176 }
00177 case EUC_LineType:
00178 {
00179 UT_Vector2 a, b, v, p;
00180
00181 a = ((EUC_Line *)obj)->getPt(0);
00182 b = ((EUC_Line *)obj)->getPt(1);
00183 v = b - a;
00184
00185
00186 ren.beginLine();
00187 p = a - 10*v;
00188 ren.vertex3DW(p.x(), p.y(), 0);
00189 ren.vertex3DW(a.x(), a.y(), 0);
00190 ren.vertex3DW(b.x(), b.y(), 0);
00191 p = b + 10*v;
00192 ren.vertex3DW(p.x(), p.y(), 0);
00193 ren.endLine();
00194 break;
00195 }
00196 case EUC_CircleType:
00197 {
00198 float t, tinc;
00199 int i, npts = 30;
00200 float radius;
00201 UT_Vector2 c, p;
00202
00203 c = ((EUC_Circle *)obj)->getCenter();
00204 radius = ((EUC_Circle *)obj)->getRadius();
00205
00206 ren.beginClosedLine();
00207 tinc = (float)(2*M_PI) / (float)(npts);
00208 for (t = 0, i = 0; i < npts; i++, t += tinc)
00209 {
00210 p = c;
00211 p.x() += radius * SYScos(t);
00212 p.y() += radius * SYSsin(t);
00213 ren.vertex3DW(p.x(), p.y(), 0);
00214 }
00215 ren.endClosedLine();
00216 }
00217 }
00218 ren.popColor();
00219 }
00220
00221 void
00222 GR_Euclid::renderShaded(GU_Detail *gdp,
00223 RE_Render &ren,
00224 const GR_AttribOffset &ptinfo,
00225 const GR_DisplayOption *dopt,
00226 float lod,
00227 const GU_PrimGroupClosure *hidden_geometry)
00228 {
00229
00230 renderWire(gdp, ren, ptinfo, dopt, lod, hidden_geometry);
00231 }
00232
00233 void
00234 newRenderHook(GR_RenderTable *table)
00235 {
00236 GR_Euclid *hook = new GR_Euclid;
00237
00238 table->addHook(hook);
00239 }
00240