00001 #include <ocean/GLvish/VRenderObject.hpp>
00002
00003 #include <fish/lakeview/bone/FishSlice.hpp>
00004 #include <fish/lakeview/bone/FishField.hpp>
00005
00006 #include <field/DirectProductArray.hpp>
00007 #include <ocean/GLvish/BoundingBox.hpp>
00008
00009 using namespace Wizt;
00010 using namespace Fiber;
00011
00012
00031 class SimpleCoords : public virtual VRenderObject, virtual public Fish<Slice>, virtual public Fish<Grid>
00032 {
00033 public:
00034
00035
00036
00037 typedef MemArray<1, Eagle::point3> CoordsArray_t;
00038
00039 TypedSlot<double> PointSize;
00040
00041
00042
00043 struct MyState : State
00044 {
00045 bool recalc_dl;
00046 RefPtr< CoordsArray_t > Crds;
00047 };
00048
00049 override RefPtr<State> newState() const
00050 {
00051 return new MyState();
00052 }
00053
00054 SimpleCoords(const string&name, int p, const RefPtr<VCreationPreferences>&VP)
00055 : VRenderObject(name, p, VP)
00056 , Fish<VObject>(this)
00057 , Fish<Grid>("coords")
00058 , PointSize(this, "pointsize", 2.0)
00059 {
00060 PointSize.setProperty("max", 10.0);
00061
00062 }
00063
00064 override bool update( VRequest&R, double precision );
00065 override void render( VRenderContext&R ) const;
00066 };
00067
00068
00069
00074 bool SimpleCoords::update( VRequest&R, double precision )
00075 {
00076
00077
00078 GridSelector GS;
00079 MyGrid << R >> GS;
00080
00081
00082 RefPtr<Grid> G = findMostRecentGrid( GS, R );
00083 if (!G) { puts("SimpleCoords::update(), ERROR: No Grid"); return true; }
00084
00085
00086 RefPtr<Field> Coords = G->CartesianPositions();
00087 if (!Coords) { puts("SimpleCoords::update(): ERROR: No coord field!"); return true; }
00088
00089
00090
00091 RefPtr<MyState> S = myState(R);
00092 assert(S);
00093
00094 S->Crds = Coords->getData();
00095 S->recalc_dl = true;
00096
00097 return true;
00098 }
00099
00100
00101 void SimpleCoords::render( VRenderContext& Context ) const
00102 {
00103
00104
00105 double point_size = 0.0;
00106 PointSize << Context >> point_size;
00107
00108 if(point_size <= 0.0) point_size = 1.0;
00109
00110 glEnable(GL_DEPTH_TEST);
00111 glDisable(GL_LIGHTING);
00112
00113 glPointSize(point_size);
00114
00115
00116 RefPtr<MyState> state = myState(Context);
00117
00118
00119 if(!state)
00120 {
00121 printf("SimpleCoords::render(): Invalid State!\n");
00122 return;
00123 }
00124 if (!state->Crds)
00125 {
00126 printf("SimpleCoords::render(): Invalid Coordinates!\n");
00127 return;
00128 }
00129
00130 RefPtr<ValueSet> RenderParameterSpace = new ValueSet();
00131
00132
00133 RefPtr<DisplayList> DL;
00134 try{
00135 DL = Context(*state)(this)( RenderParameterSpace );
00136 }
00137 catch(...){}
00138 if ( DL && !state->recalc_dl )
00139 {
00140 if(DL->call())
00141 {
00142
00143 return;
00144 }
00145 }
00146 else
00147 {
00148 DL = Context[*state][this][ RenderParameterSpace ];
00149 if (!DL) throw "SimpleCoords::render() No Display List!?";
00150
00151 state->recalc_dl = false;
00152
00153
00154
00155
00156
00157 if (state->Crds)
00158 {
00159 point Start = state->Crds->first();
00160 point End = state->Crds->last();
00161 setBoundingBall(Context, new BoundingBox(Start, End) );
00162 printf("SimpleCoords::render(): got numerical coordinates\n" );
00163 }
00164
00165
00166 MultiIndex<1> M;
00167 MultiArray<1, point>&Cr = *state->Crds;
00168
00169 glCompile( *DL )
00170 {
00171 printf("SimpleCoords::render(): compiling new list\n");
00172 glBegin(GL_POINTS);
00173 glColor3f(1.0,1.0,1.0);
00174
00175 do
00176 {
00177 point Vertex;
00178
00179 Vertex = Cr[M];
00180
00181 glVertex(Vertex);
00182
00183 }
00184 while( M.inc( Cr.Size() ) );
00185
00186 glEnd();
00187
00188 }
00189 }
00190 }
00191
00192
00193 static Ref<VCreator<SimpleCoords, AcceptList<Fiber::Grid> > > myCreator("Tutorial/SimpleCoords");
00194
00195 VISH_DEFAULT_INIT