source: ThirdParty/mpqc_open/src/lib/util/render/render.cc@ 7516f6

Action_Thermostats Adding_MD_integration_tests Adding_StructOpt_integration_tests AutomationFragmentation_failures Candidate_v1.6.1 ChemicalSpaceEvaluator Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Exclude_Hydrogens_annealWithBondGraph Fix_Verbose_Codepatterns ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion Gui_displays_atomic_force_velocity JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool PythonUI_with_named_parameters Recreated_GuiChecks StoppableMakroAction TremoloParser_IncreasedPrecision
Last change on this file since 7516f6 was 860145, checked in by Frederik Heber <heber@…>, 8 years ago

Merge commit '0b990dfaa8c6007a996d030163a25f7f5fc8a7e7' as 'ThirdParty/mpqc_open'

  • Property mode set to 100644
File size: 6.7 KB
Line 
1//
2// render.cc
3//
4// Copyright (C) 1996 Limit Point Systems, Inc.
5//
6// Author: Curtis Janssen <cljanss@limitpt.com>
7// Maintainer: LPS
8//
9// This file is part of the SC Toolkit.
10//
11// The SC Toolkit is free software; you can redistribute it and/or modify
12// it under the terms of the GNU Library General Public License as published by
13// the Free Software Foundation; either version 2, or (at your option)
14// any later version.
15//
16// The SC Toolkit is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU Library General Public License for more details.
20//
21// You should have received a copy of the GNU Library General Public License
22// along with the SC Toolkit; see the file COPYING.LIB. If not, write to
23// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24//
25// The U.S. Government is granted a limited license as per AL 91-7.
26//
27
28#ifdef __GNUC__
29#pragma implementation
30#endif
31
32#include <util/misc/formio.h>
33
34#include <util/render/render.h>
35#include <util/render/object.h>
36#include <util/render/animate.h>
37#include <util/render/find.h>
38#include <util/render/polygons.h>
39#include <util/render/polysphere.h>
40
41using namespace std;
42using namespace sc;
43
44/////////////////////////////////////////////////////////////////////////////
45// Render
46
47static ClassDesc Render_cd(
48 typeid(Render),"Render",1,"public DescribedClass",
49 0, 0, 0);
50
51Render::Render()
52{
53}
54
55Render::Render(const Ref<KeyVal>& keyval)
56{
57}
58
59Render::~Render()
60{
61}
62
63void
64Render::push_material(const Ref<Material>& m)
65{
66 material_stack_.push(m);
67}
68
69void
70Render::push_appearance(const Ref<Appearance>& a)
71{
72 appearance_stack_.push(a);
73}
74
75void
76Render::push_transform(const Ref<Transform>& t)
77{
78 transform_stack_.push(t);
79}
80
81Ref<Material>
82Render::pop_material()
83{
84 return material_stack_.pop();
85}
86
87Ref<Appearance>
88Render::pop_appearance()
89{
90 return appearance_stack_.pop();
91}
92
93Ref<Transform>
94Render::pop_transform()
95{
96 return transform_stack_.pop();
97}
98
99void
100Render::render(const Ref<RenderedObject>& object)
101{
102 if (object->material().nonnull()) push_material(object->material());
103 if (object->transform().nonnull()) push_transform(object->transform());
104 if (object->appearance().nonnull()) push_appearance(object->appearance());
105 object->render(this);
106 if (object->material().nonnull()) pop_material();
107 if (object->transform().nonnull()) pop_transform();
108 if (object->appearance().nonnull()) pop_appearance();
109}
110
111void
112Render::set(const Ref<RenderedObjectSet>& set)
113{
114 for (int i=0; i<set->n(); i++) {
115 render(set->element(i));
116 }
117}
118
119// This renders spheres by creating a RenderedPolygon object
120void
121Render::sphere(const Ref<RenderedSphere>& sphere)
122{
123 // find the level of accuracy which should be used to render the sphere
124 int level = 1;
125 find_int_parameter_in_appearance_stack(appearance_stack_,
126 &Appearance::level,
127 level);
128 Ref<RenderedPolygons> poly(new RenderedPolygons);
129
130 polysphere(level, poly.pointer());
131
132 render(poly.pointer());
133}
134
135void
136Render::animate(const Ref<AnimatedObject> &animated_object)
137{
138 for (int i=0; i<animated_object->nobject(); i++) {
139 Ref<RenderedObject> object = animated_object->object(i);
140 render(object);
141 }
142}
143
144/////////////////////////////////////////////////////////////////////////////
145// FileRender
146
147static ClassDesc FileRender_cd(
148 typeid(FileRender),"FileRender",1,"public Render",
149 0, 0, 0);
150
151FileRender::FileRender(const char * filename)
152{
153 filename_ = 0;
154 basename_ = 0;
155 depth_ = 0;
156 sbuf_ = 0;
157 delete_sbuf_ = 0;
158 set_filename(filename);
159}
160
161FileRender::FileRender(ostream &o)
162{
163 filename_ = 0;
164 basename_ = 0;
165 depth_ = 0;
166 sbuf_ = o.rdbuf();
167 delete_sbuf_ = 0;
168}
169
170FileRender::FileRender(const Ref<KeyVal>& keyval):
171 Render(keyval)
172{
173 char *filename = keyval->pcharvalue("filename");
174 char *basename = keyval->pcharvalue("basename");
175 if (!filename && !basename) {
176 const char *cbasename = SCFormIO::default_basename();
177 if (cbasename) {
178 basename = strcpy(new char[strlen(cbasename)+1],cbasename);
179 }
180 }
181 depth_ = 0;
182 sbuf_ = 0;
183 delete_sbuf_ = 0;
184 filename_ = 0;
185 basename_ = 0;
186 if (basename) {
187 set_basename(basename);
188 delete[] basename;
189 }
190 // filename overrides basename
191 if (filename) {
192 set_filename(filename);
193 delete[] filename;
194 }
195}
196
197void
198FileRender::set_filename(const char *filename)
199{
200 delete[] basename_;
201 delete[] filename_;
202 filename_ = 0;
203 basename_ = 0;
204 if (filename) filename_ = strcpy(new char[strlen(filename)+1],filename);
205}
206
207void
208FileRender::set_basename(const char *basename)
209{
210 delete[] filename_;
211 delete[] basename_;
212 filename_ = 0;
213 basename_ = 0;
214 if (basename) basename_ = strcpy(new char[strlen(basename)+1],basename);
215}
216
217FileRender::~FileRender()
218{
219 delete[] filename_;
220 delete[] basename_;
221 if (delete_sbuf_) delete sbuf_;
222}
223
224void
225FileRender::clear()
226{
227}
228
229char *
230FileRender::get_filename(const char *objectname)
231{
232 char *file = 0;
233
234 if (filename_) {
235 // if a file name is given then it is the entire name of the file
236 file = strcpy(new char[strlen(filename_) + 1],filename_);
237 }
238 else if (basename_) {
239 // if we have a base name, it is used to construct a filename
240 const char *ext = file_extension();
241 int lenobjectname;
242 if (objectname == 0) lenobjectname = 0;
243 else lenobjectname = strlen(objectname);
244 if (lenobjectname) lenobjectname++;
245 file = new char[strlen(basename_)+lenobjectname+strlen(ext)+1];
246 strcpy(file, basename_);
247 if (lenobjectname) {
248 strcat(file, ".");
249 strcat(file, objectname);
250 }
251 strcat(file, ext);
252 }
253 else {
254 if (!objectname) objectname = "renderedobject";
255 const char *ext = file_extension();
256 file = new char[strlen(objectname)+strlen(ext)+1];
257 strcpy(file, objectname);
258 strcat(file, ext);
259 }
260
261 return file;
262}
263
264void
265FileRender::open_sbuf(const char *objectname)
266{
267 if (depth_++) return;
268
269 char *file = get_filename(objectname);
270
271 if (file) {
272 filebuf *fbuf = new filebuf();
273 fbuf->open(file,ios::out);
274 if (!fbuf->is_open()) {
275 ExEnv::errn() << scprintf("FileRender: couldn't open \"%s\"\n", filename_);
276 abort();
277 }
278 sbuf_ = fbuf;
279 delete_sbuf_ = 1;
280 delete[] file;
281 }
282}
283
284void
285FileRender::close_sbuf()
286{
287 if (--depth_ > 0) return;
288
289 if (delete_sbuf_) {
290 delete sbuf_;
291 sbuf_ = 0;
292 delete_sbuf_ = 0;
293 }
294}
295
296const char *
297FileRender::file_extension()
298{
299 return ".ren";
300}
301
302/////////////////////////////////////////////////////////////////////////////
303
304// Local Variables:
305// mode: c++
306// c-file-style: "CLJ"
307// End:
Note: See TracBrowser for help on using the repository browser.