1 /*
2   Teem: Tools to process and visualize scientific data and images             .
3   Copyright (C) 2012, 2011, 2010, 2009  University of Chicago
4   Copyright (C) 2008, 2007, 2006, 2005  Gordon Kindlmann
5   Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998  University of Utah
6 
7   This library is free software; you can redistribute it and/or
8   modify it under the terms of the GNU Lesser General Public License
9   (LGPL) as published by the Free Software Foundation; either
10   version 2.1 of the License, or (at your option) any later version.
11   The terms of redistributing and/or modifying this software also
12   include exceptions to the LGPL that facilitate static linking.
13 
14   This library is distributed in the hope that it will be useful,
15   but WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17   Lesser General Public License for more details.
18 
19   You should have received a copy of the GNU Lesser General Public License
20   along with this library; if not, write to Free Software Foundation, Inc.,
21   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 */
23 
24 #include "echo.h"
25 #include "privateEcho.h"
26 
27 int
28 echoObjectHasMatter[ECHO_TYPE_NUM] = {
29   1, /* echoTypeSphere */
30   1, /* echoTypeCylinder */
31   1, /* echoTypeSuperquad */
32   1, /* echoTypeCube */
33   1, /* echoTypeTriangle */
34   1, /* echoTypeRectangle */
35   1, /* echoTypeTriMesh */
36   1, /* echoTypeIsosurface */
37   0, /* echoTypeAABBox */
38   0, /* echoTypeSplit */
39   0, /* echoTypeList */
40   0, /* echoTypeInstance */
41 };
42 
43 void
echoColorSet(echoObject * obj,echoCol_t R,echoCol_t G,echoCol_t B,echoCol_t A)44 echoColorSet(echoObject *obj,
45              echoCol_t R, echoCol_t G, echoCol_t B, echoCol_t A) {
46 
47   if (obj && echoObjectHasMatter[obj->type]) {
48     ELL_4V_SET(obj->rgba, R, G, B, A);
49   }
50 }
51 
52 void
echoMatterPhongSet(echoScene * scene,echoObject * obj,echoCol_t ka,echoCol_t kd,echoCol_t ks,echoCol_t sp)53 echoMatterPhongSet(echoScene *scene, echoObject *obj,
54                    echoCol_t ka, echoCol_t kd, echoCol_t ks, echoCol_t sp) {
55 
56   if (scene && obj && echoObjectHasMatter[obj->type]) {
57     obj->matter = echoMatterPhong;
58     obj->mat[echoMatterPhongKa] = ka;
59     obj->mat[echoMatterPhongKd] = kd;
60     obj->mat[echoMatterPhongKs] = ks;
61     obj->mat[echoMatterPhongSp] = sp;
62   }
63 }
64 
65 void
echoMatterGlassSet(echoScene * scene,echoObject * obj,echoCol_t indexr,echoCol_t ka,echoCol_t kd,echoCol_t fuzzy)66 echoMatterGlassSet(echoScene *scene, echoObject *obj,
67                    echoCol_t indexr, echoCol_t ka,
68                    echoCol_t kd, echoCol_t fuzzy) {
69 
70   if (scene && obj && echoObjectHasMatter[obj->type]) {
71     obj->matter = echoMatterGlass;
72     obj->mat[echoMatterGlassIndex] = indexr;
73     obj->mat[echoMatterGlassKa] = ka;
74     obj->mat[echoMatterGlassKd] = kd;
75     obj->mat[echoMatterGlassFuzzy] = fuzzy;
76   }
77 }
78 
79 void
echoMatterMetalSet(echoScene * scene,echoObject * obj,echoCol_t R0,echoCol_t ka,echoCol_t kd,echoCol_t fuzzy)80 echoMatterMetalSet(echoScene *scene, echoObject *obj,
81                    echoCol_t R0, echoCol_t ka,
82                    echoCol_t kd, echoCol_t fuzzy) {
83 
84   if (scene && obj && echoObjectHasMatter[obj->type]) {
85     obj->matter = echoMatterMetal;
86     obj->mat[echoMatterMetalR0] = R0;
87     obj->mat[echoMatterMetalKa] = ka;
88     obj->mat[echoMatterMetalKd] = kd;
89     obj->mat[echoMatterMetalFuzzy] = fuzzy;
90   }
91 }
92 
93 void
echoMatterLightSet(echoScene * scene,echoObject * obj,echoCol_t power,echoCol_t unit)94 echoMatterLightSet(echoScene *scene, echoObject *obj,
95                    echoCol_t power, echoCol_t unit) {
96 
97   if (scene && obj && echoObjectHasMatter[obj->type]) {
98     obj->matter = echoMatterLight;
99     obj->mat[echoMatterLightPower] = power;
100     obj->mat[echoMatterLightUnit] = unit;
101     /* HEY: god forbid we should change the material of the light after this */
102     _echoSceneLightAdd(scene, obj);
103   }
104 }
105 
106 void
echoMatterTextureSet(echoScene * scene,echoObject * obj,Nrrd * ntext)107 echoMatterTextureSet(echoScene *scene, echoObject *obj, Nrrd *ntext) {
108 
109   if (scene && obj && ntext && echoObjectHasMatter[obj->type] &&
110       3 == ntext->dim &&
111       nrrdTypeUChar == ntext->type &&
112       4 == ntext->axis[0].size) {
113     obj->ntext = ntext;
114     _echoSceneNrrdAdd(scene, ntext);
115   }
116 }
117