@@ -60,190 +60,192 @@ void ShowColorMapModule::setStateDefaults()
6060
6161void ShowColorMapModule::execute ()
6262{
63- // ColorMapHandle cmHandle = 0;
64- // if (!get_input_handle("ColorMap", cmHandle, true)) return;
63+ #ifdef SCIRUN4_CODE_TO_BE_ENABLED_LATER
64+ ColorMapHandle cmHandle = 0 ;
65+ if (!get_input_handle (" ColorMap" , cmHandle, true )) return ;
6566
66- // if (inputs_changed_ ||
67- // !geometry_output_handle_.get_rep() ||
68- // gui_length_.changed(true) ||
69- // gui_side_.changed(true) ||
70- // gui_numlabels_.changed(true) ||
71- // gui_scale_.changed(true) ||
72- // gui_num_sig_digits_.changed(true) ||
73- // gui_units_.changed(true) ||
74- // gui_text_fontsize_.changed(true) ||
75- // gui_extra_padding_.changed(true) ||
76- // color_changed_ == true)
77- // {
78- // // Inform module that execution started
79- // update_state(Executing);
67+ if (inputs_changed_ ||
68+ !geometry_output_handle_.get_rep () ||
69+ gui_length_.changed (true ) ||
70+ gui_side_.changed (true ) ||
71+ gui_numlabels_.changed (true ) ||
72+ gui_scale_.changed (true ) ||
73+ gui_num_sig_digits_.changed (true ) ||
74+ gui_units_.changed (true ) ||
75+ gui_text_fontsize_.changed (true ) ||
76+ gui_extra_padding_.changed (true ) ||
77+ color_changed_ == true )
78+ {
79+ // Inform module that execution started
80+ update_state (Executing);
8081
81- // GeomGroup *all = new GeomGroup();
82+ GeomGroup *all = new GeomGroup ();
8283
83- // Point ref1(0.0, 0.0, 0.0);
84- // Vector out(0.0, 0.0, 0.0);
85- // Vector along(0.0, 0.0, 0.0);
84+ Point ref1 (0.0 , 0.0 , 0.0 );
85+ Vector out (0.0 , 0.0 , 0.0 );
86+ Vector along (0.0 , 0.0 , 0.0 );
8687
87- // color_changed_ = false;
88+ color_changed_ = false ;
8889
89- // text_material_handle_->diffuse =
90- // Color(gui_color_r_.get(), gui_color_g_.get(), gui_color_b_.get());
90+ text_material_handle_->diffuse =
91+ Color (gui_color_r_.get (), gui_color_g_.get (), gui_color_b_.get ());
9192
92- // if (gui_side_.get() == "left")
93- // {
94- // out = Vector(-0.05, 0.0, 0.0);
95- // if (gui_length_.get() == "full" || gui_length_.get() == "half2")
96- // {
97- // if (gui_extra_padding_.get())
98- // {
99- // ref1 = Point(-1.0, -14.0 / 16.0, 0.0);
100- // }
101- // else
102- // {
103- // ref1 = Point(-1.0, -15.0 / 16.0, 0.0);
104- // }
105- // }
106- // else
107- // {
108- // ref1 = Point(-1.0, 1.0 / 16.0, 1.0);
109- // }
93+ if (gui_side_.get () == " left" )
94+ {
95+ out = Vector (-0.05 , 0.0 , 0.0 );
96+ if (gui_length_.get () == " full" || gui_length_.get () == " half2" )
97+ {
98+ if (gui_extra_padding_.get ())
99+ {
100+ ref1 = Point (-1.0 , -14.0 / 16.0 , 0.0 );
101+ }
102+ else
103+ {
104+ ref1 = Point (-1.0 , -15.0 / 16.0 , 0.0 );
105+ }
106+ }
107+ else
108+ {
109+ ref1 = Point (-1.0 , 1.0 / 16.0 , 1.0 );
110+ }
110111
111- // if (gui_length_.get() == "full")
112- // {
113- // if (gui_extra_padding_.get())
114- // {
115- // along = Vector(0.0, 29.0 / 16.0, 0.0);
116- // }
117- // else
118- // {
119- // along = Vector(0.0, 30.0 / 16.0, 0.0);
120- // }
121- // }
122- // else
123- // {
124- // along = Vector(0.0, 14.0 / 16.0, 0.0);
125- // }
126- // }
127- // else if (gui_side_.get() == "bottom")
128- // {
129- // out = Vector(0.0, -0.05, 0.0);
130- // if (gui_length_.get() == "full" || gui_length_.get() == "half1")
131- // {
132- // ref1 = Point(-15.0 / 16.0, -1.0, 0.0);
133- // }
134- // else
135- // {
136- // ref1 = Point(1.0 / 16.0, -1.0, 0.0);
137- // }
112+ if (gui_length_.get () == " full" )
113+ {
114+ if (gui_extra_padding_.get ())
115+ {
116+ along = Vector (0.0 , 29.0 / 16.0 , 0.0 );
117+ }
118+ else
119+ {
120+ along = Vector (0.0 , 30.0 / 16.0 , 0.0 );
121+ }
122+ }
123+ else
124+ {
125+ along = Vector (0.0 , 14.0 / 16.0 , 0.0 );
126+ }
127+ }
128+ else if (gui_side_.get () == " bottom" )
129+ {
130+ out = Vector (0.0 , -0.05 , 0.0 );
131+ if (gui_length_.get () == " full" || gui_length_.get () == " half1" )
132+ {
133+ ref1 = Point (-15.0 / 16.0 , -1.0 , 0.0 );
134+ }
135+ else
136+ {
137+ ref1 = Point (1.0 / 16.0 , -1.0 , 0.0 );
138+ }
138139
139- // if (gui_length_.get() == "full")
140- // {
141- // if (gui_extra_padding_.get())
142- // {
143- // along = Vector(29.0 / 16.0, 0.0, 0.0);
144- // }
145- // else
146- // {
147- // along = Vector(30.0 / 16.0, 0.0, 0.0);
148- // }
149- // }
150- // else
151- // {
152- // if (gui_extra_padding_.get())
153- // {
154- // along = Vector(13.0 / 16.0, 0.0, 0.0);
155- // }
156- // else
157- // {
158- // along = Vector(14.0 / 16.0, 0.0, 0.0);
159- // }
160- // }
161- // }
140+ if (gui_length_.get () == " full" )
141+ {
142+ if (gui_extra_padding_.get ())
143+ {
144+ along = Vector (29.0 / 16.0 , 0.0 , 0.0 );
145+ }
146+ else
147+ {
148+ along = Vector (30.0 / 16.0 , 0.0 , 0.0 );
149+ }
150+ }
151+ else
152+ {
153+ if (gui_extra_padding_.get ())
154+ {
155+ along = Vector (13.0 / 16.0 , 0.0 , 0.0 );
156+ }
157+ else
158+ {
159+ along = Vector (14.0 / 16.0 , 0.0 , 0.0 );
160+ }
161+ }
162+ }
162163
163- // const Point ref0(ref1 - out);
164- // // Create a new colormap that we can send to ColorMapTex. We need
165- // // to do this, because if the colormap min/max are too close you get
166- // // problems. This is because the min and max are used to lookup
167- // // into the texture as floats. Precion problems occur when the min
168- // // == max in floats, but not as doubles.
169- // ColorMapHandle cmap_rescaled;
170- // // Only rescale it when the min != max or min and max are too close.
171- // float too_close = Abs((float)(cmHandle->getMin()) - (float)(cmHandle->getMax()));
172- // // Replace zero compared with too_close with an epsilon if desired.
173- // if (too_close <= 0)
174- // {
175- // // Make a copy of the colormap we can rescale
176- // cmap_rescaled = cmHandle->clone();
177- // cmap_rescaled->Scale(0, 1);
178- // }
179- // else
180- // {
181- // cmap_rescaled = cmHandle;
182- // }
164+ const Point ref0 (ref1 - out);
165+ // Create a new colormap that we can send to ColorMapTex. We need
166+ // to do this, because if the colormap min/max are too close you get
167+ // problems. This is because the min and max are used to lookup
168+ // into the texture as floats. Precion problems occur when the min
169+ // == max in floats, but not as doubles.
170+ ColorMapHandle cmap_rescaled;
171+ // Only rescale it when the min != max or min and max are too close.
172+ float too_close = Abs ((float )(cmHandle->getMin ()) - (float )(cmHandle->getMax ()));
173+ // Replace zero compared with too_close with an epsilon if desired.
174+ if (too_close <= 0 )
175+ {
176+ // Make a copy of the colormap we can rescale
177+ cmap_rescaled = cmHandle->clone ();
178+ cmap_rescaled->Scale (0 , 1 );
179+ }
180+ else
181+ {
182+ cmap_rescaled = cmHandle;
183+ }
183184
184- // ColorMapTex *sq = new ColorMapTex(ref0, ref0 + along,
185- // ref0 + along + out, ref0 + out, cmap_rescaled);
186- // all->add(sq);
185+ ColorMapTex *sq = new ColorMapTex (ref0, ref0 + along,
186+ ref0 + along + out, ref0 + out, cmap_rescaled);
187+ all->add (sq);
187188
188- // double scale = gui_scale_.get();
189- // std::string str = gui_units_.get();
190- // if (str.empty()) str = cmHandle->units();
191- // // So if the maximum number of digits the number will take up is
192- // // at most 25 then the length of str better be less than 80-25-1.
193- // // See size of value and num_sig_digits below.
194- // if (str.length() > 50)
195- // {
196- // error("Length of units string is too long. Make it smaller than 50 characters please.");
197- // return;
198- // }
189+ double scale = gui_scale_.get ();
190+ std::string str = gui_units_.get ();
191+ if (str.empty ()) str = cmHandle->units ();
192+ // So if the maximum number of digits the number will take up is
193+ // at most 25 then the length of str better be less than 80-25-1.
194+ // See size of value and num_sig_digits below.
195+ if (str.length () > 50 )
196+ {
197+ error (" Length of units string is too long. Make it smaller than 50 characters please." );
198+ return ;
199+ }
199200
200- // const int numlabels = gui_numlabels_.get();
201- // if (numlabels > 1 && numlabels < 50)
202- // {
203- // // Fill in the text.
204- // const double minval = cmHandle->getMin()*scale;
205- // const double maxval = cmHandle->getMax()*scale;
201+ const int numlabels = gui_numlabels_.get ();
202+ if (numlabels > 1 && numlabels < 50 )
203+ {
204+ // Fill in the text.
205+ const double minval = cmHandle->getMin ()*scale;
206+ const double maxval = cmHandle->getMax ()*scale;
206207
207- // Point p0 = ref0 - out * 0.02;
208- // char value[80];
209- // GeomLines *lines = new GeomLines();
210- // GeomTexts *texts = new GeomTexts();
211- // texts->set_is_2d(true);
212- // texts->set_font_index(gui_text_fontsize_.get());
213- // int num_sig_digits = gui_num_sig_digits_.get();
214- // if (num_sig_digits < 1)
215- // {
216- // warning("Number of significant digits needs to be at least 1. Setting the number of significant digits to 1.");
217- // gui_num_sig_digits_.set(1);
218- // num_sig_digits = 1;
219- // }
220- // if (num_sig_digits > 20)
221- // {
222- // warning("Number of significant digits needs to be less than or equal to 20. Setting the number of significant digits to 20");
223- // gui_num_sig_digits_.set(20);
224- // num_sig_digits = 20;
225- // }
226- // for (int i = 0; i < numlabels; i++)
227- // {
228- // sprintf(value, "%.*g %s", num_sig_digits,
229- // minval + (maxval - minval)*(i / (numlabels - 1.0)),
230- // str.c_str());
231- // const Point loc = p0 + along * (i / (numlabels - 1.0));
232- // texts->add(value, loc, text_material_handle_->diffuse);
233- // lines->add(loc, text_material_handle_,
234- // loc + out * 0.5, text_material_handle_);
235- // }
208+ Point p0 = ref0 - out * 0.02 ;
209+ char value[80 ];
210+ GeomLines *lines = new GeomLines ();
211+ GeomTexts *texts = new GeomTexts ();
212+ texts->set_is_2d (true );
213+ texts->set_font_index (gui_text_fontsize_.get ());
214+ int num_sig_digits = gui_num_sig_digits_.get ();
215+ if (num_sig_digits < 1 )
216+ {
217+ warning (" Number of significant digits needs to be at least 1. Setting the number of significant digits to 1." );
218+ gui_num_sig_digits_.set (1 );
219+ num_sig_digits = 1 ;
220+ }
221+ if (num_sig_digits > 20 )
222+ {
223+ warning (" Number of significant digits needs to be less than or equal to 20. Setting the number of significant digits to 20" );
224+ gui_num_sig_digits_.set (20 );
225+ num_sig_digits = 20 ;
226+ }
227+ for (int i = 0 ; i < numlabels; i++)
228+ {
229+ sprintf (value, " %.*g %s" , num_sig_digits,
230+ minval + (maxval - minval)*(i / (numlabels - 1.0 )),
231+ str.c_str ());
232+ const Point loc = p0 + along * (i / (numlabels - 1.0 ));
233+ texts->add (value, loc, text_material_handle_->diffuse );
234+ lines->add (loc, text_material_handle_,
235+ loc + out * 0.5 , text_material_handle_);
236+ }
236237
237- // all->add(texts);
238- // all->add(lines);
239- // }
238+ all->add (texts);
239+ all->add (lines);
240+ }
240241
241- // GeomSticky *sticky = new GeomSticky(all);
242- // geometry_output_handle_ = GeomHandle(sticky);
242+ GeomSticky *sticky = new GeomSticky (all);
243+ geometry_output_handle_ = GeomHandle (sticky);
243244
244- // send_output_handle("Geometry", geometry_output_handle_, "ShowColorMap Sticky");
245- // }
246- // sendOutput(ColorMapObject, StandardColorMapFactory::create(get_state()->getValue(Variables::ColorMapName).toString()));
245+ send_output_handle (" Geometry" , geometry_output_handle_, " ShowColorMap Sticky" );
246+ }
247+ sendOutput (ColorMapObject, StandardColorMapFactory::create (get_state ()->getValue (Variables::ColorMapName).toString ()));
248+ #endif
247249}
248250
249251AlgorithmParameterName ShowColorMapModule::DisplaySide (" DisplaySide" );
0 commit comments