Loading [MathJax]/extensions/TeX/AMSsymbols.js
LAL 7.7.0.1-00ddc7f
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
LALMathNDPlot.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Chad Hanna, Benjamin Owen
3*
4* This program is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License as published by
6* the Free Software Foundation; either version 2 of the License, or
7* (at your option) any later version.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12* GNU General Public License for more details.
13*
14* You should have received a copy of the GNU General Public License
15* along with with program; see the file COPYING. If not, write to the
16* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17* MA 02110-1301 USA
18*/
19
20/*_______________________________________________________________________________________
21 *
22 * File Name: LALMathNDPlot.c
23 *
24 * Author: Hanna C. R.
25 *
26 *_______________________________________________________________________________________
27 */
28
29#include <lal/LALConfig.h>
30#include <lal/LALMalloc.h>
31#include <lal/LALStatusMacros.h>
32#include <lal/LALStdlib.h>
33#include <lal/LALMathematica.h>
34#include <lal/LALStdio.h>
35
36
37#define INSTRUCTIONS fprintf(nb, "Running this entire notebook using ctrl+A and shift+enter may crash your computer. Evaluate each section as needed. The Initialization and User Variables sections must be evaluated first. The 3-dimensional projections are represented in the sections below User Varibles as PointList (x1, x2, x3) etc. Evaluating the entire Image Generation sections creates animated plots (if AnimationPlot := True). If (AnimationPlot := False) you get only still plots, saving time and memory.")
38
39/**
40 * \brief This function is for plotting N-Dimensional template banks by creating
41 * a MATHEMATICA notebook.
42 *
43 * \ingroup LALMathematica_h
44 * \author Hanna, C. R.
45 *
46 * The notebook renders the templates as points in all of the
47 * 3-Dimensional projection permutations. Each projection may be animated so the user
48 * can see the template bank from different perspectives.
49 *
50 * ### Notes ###
51 *
52 * <ul>
53 * <li> The output of this function is &quot;MathNDNotebook.nb&quot; will appear in the
54 * directory of the program that called this function.</li>
55 * <li> Exported MATHEMATICA graphics will appear in
56 * your home directory for unix users and in the \\Mathematica directory for
57 * Windows users unless you have another path configured in your MATHEMATICA
58 * installation. It is necessary to change the file name within the notebook to avoid
59 * overwriting previous files.</li>
60 * <li> The number of projections is N!/(3!(N-3)!). Thus plotting 6 dimensions would
61 * produce 20 projections, 7 dimensions would yeilds 35 amd 8 gives 56.</li>
62 * </ul>
63 *
64 */
65void
66LALMathNDPlot( LALStatus *stat, /**< LALStatus structure pointer */
67 MathNDPointList *first, /**< MathNDPointList stucture pointer */
68 INT4 *ntiles, /**< INT4 pointer to the number of templates you \e plan to plot.
69 * This may be called as NULL. If it is called with a value this function will check
70 * to see if the MathNDPointList has the correct number of templates. If it does not
71 * a warning will be printed. */
72 REAL4 *pointSize /**< \f$\epsilon[0,1]\f$ which specifies the relative size of each
73 * point to the final display area. (e.g. 1 would fill the enire plot.) This may be
74 * called as NULL and a calculated value will be assigned. (Its only a rough guess) */
75 )
76
77{
78 FILE *nb; /* pointer to the notebook file */
79 INT4 jflag = 0; /* flag to justify the output data */
80 MathNDPointList *list; /* loop counter */
81 REAL4 PtSize = 0.02;
82 INT4 counter = 0;
83 INT4 dim = first->coordinates->length;
84 INT4 x = 0;
85 INT4 y = 0;
86 INT4 z = 0;
87
88
89 INITSTATUS(stat);
90
91 /* Check that the PointList isn't NULL */
92 if (!first) {
93 ABORT(stat, LALMATHEMATICAH_ENULL, LALMATHEMATICAH_MSGENULL);
94 }
95
96 /* Open a file for writing a notebook */
97 if ((nb = LALFopen("MathNDNotebook.nb", "w")) == NULL) {
98 ABORT(stat, LALMATHEMATICAH_EFILE, LALMATHEMATICAH_MSGEFILE);
99 }
100
101 /* Appropriately handle the inputs for ntiles and pointsize to assure
102 that a propter pointSize is chosen. Also print a warning if the
103 length of the MathNDPointList is not equal in length to the parameter
104 ntiles passed to this function. */
105 if (!pointSize){
106 if (!ntiles){
107 list=first;
108 while(list->next){
109 counter++;
110 list=list->next;
111 }
112 ntiles = &counter;
113 }
114 else{
115 list=first;
116 while(list->next){
117 counter++;
118 list=list->next;
119 }
120 if (*ntiles != counter)
121 printf("\nWARNING!!! The value of argument ntiles (%i) != the MathNDPointList length (%i)\n",
122 *ntiles, counter);
123 }
124 if (*ntiles <=0) {
125 ABORT(stat, LALMATHEMATICAH_EVAL, LALMATHEMATICAH_MSGEVAL);
126 }
127 PtSize = 0.50*(1.0/(pow((*ntiles),0.333333)));
128 if (*ntiles > 10000)
129 printf("\nWARNING!!! More than 10,000 tiles may crash Mathematica:)\n");
130 }
131
132 else{
133 if ((*pointSize <= 0.0) || (*pointSize >= 1.0)) {
134 printf("\nIllegal value of pointSize; it must be between 0 and 1.\n");
135 printf("The default value of 0.02 will be used");
136 PtSize = 0.02;
137 }
138 }
139
140 /* The code that generates the notebook */
143 fprintf(nb, "LALMath3D Output");
146 fprintf(nb, "Instructions");
153 fprintf(nb, "Initialization");
156 fprintf(nb, "Off[General::spell];");
159 fprintf(nb, "Off[General::spell1];");
163 fprintf(nb, "User Variables");
167 fprintf(nb, "AnimationPlot\t:= False;");
170 fprintf(nb, "AnimationSize\t= {400,400};");
173 fprintf(nb, "StillSize\t= {600,600};");
176 fprintf(nb, "PtSize\t= %f;", PtSize);
179 fprintf(nb, "AnimationName\t:= \"AnimationTilePlot\""); /* dont forget to giv a unique name */
182 fprintf(nb, "StillName\t:= \"StillTilePlot\""); /* dont forget to give a unique name for each section */
185 fprintf(nb, "StillType\t:=\"EPS\"");
188 fprintf(nb, "frames\t= 30;");
191 fprintf(nb, "FrameTime\t= 0.2;");
193 for(counter = 1; counter <= dim; counter++){
194 BEG_INPUTCELL; /* Create an axis label for each dimension */
195 fprintf(nb, "X%iAxisLabel := \"x%i\"", counter, counter);
197 }
199 fprintf(nb, "AnimationPlot:\tFlag to set for generating animations (may take a while to run)\n");
200 fprintf(nb, "AnimationSize:\tThe size of the final animation in PIXELS x PIXELS\n");
201 fprintf(nb, "StillSize:\t\tThe size of the final still image in PIXELS x PIXELS\n");
202 fprintf(nb, "PtSize:\t\tThe relative size of the template points to the final display width.\n");
203 fprintf(nb, "\t\t\tIt is given as a decimal part of one. (e.g. PtSize=0.02 is 1/20 of the display width)\n");
204 fprintf(nb, "AnimationName:\tWhat to name the final animation.\n");
205 fprintf(nb, "StillName:\t\tWhat to name the final still image - extension determined by StillType\n");
206 fprintf(nb, "StillType:\t\tThe file type and extension for the still image\n");
207 fprintf(nb, "\t\t\tChoose any standard format (e.g. JPG, GIF, PDF, EPS, etc.)\n");
208 fprintf(nb, "frames:\t\tThe number of frames for each rotation of the image.\n");
209 fprintf(nb, "\t\t\tThe final image will have 2 times the number frames\n");
210 fprintf(nb, "FrameTime:\t\tSets the delay time in seconds between each frame in the animated gif\n");
211 fprintf(nb, "\t\t\tApplications seem to interpret this differently. You may have to adjust this setting\n");
212 fprintf(nb, "\t\t\tbased on the intended application of the animations.\n");
213 fprintf(nb, "XiAxisLabel:\t\tSets the Xi-axis label\n");
216 /* begin iterations of projection permutations */
217 for(x = 0; x < dim; x++){
218 for(y = (x+1); y < dim; y++){
219 for(z = (y+1); z < dim; z++){
223 fprintf(nb, "Point List (x%i,x%i,x%i)", (x+1), (y+1), (z+1));
226 fprintf(nb, "TILES%i%i%i = \n", (x+1), (y+1), (z+1));
227 fprintf(nb, "Graphics3D[{PointSize[PtSize]");
228 list = first;
229 while(list->next)
230 {
231 fprintf(nb, ",{GrayLevel[%f], Point[{%f,%f,%f}]}",
232 list->grayLevel, list->coordinates->data[x], list->coordinates->data[y], list->coordinates->data[z]);
233 if (jflag%2) fprintf(nb,"\n");
234 ++jflag;
235 list = list->next;
236 }
237 fprintf(nb, "}]");
242 fprintf(nb, "Image generation (x%i,x%i,x%i)", (x+1), (y+1), (z+1));
245 fprintf(nb, "still%i%i%i = Show[TILES%i%i%i, Background-> RGBColor[.93, .91, .89], ViewPoint -> {1, 1.3, 2.4}, ",
246 (x+1), (y+1), (z+1), (x+1), (y+1), (z+1));
247 fprintf(nb, "ImageSize->StillSize, Axes->True, AxesLabel->{X%iAxisLabel, X%iAxisLabel, X%iAxisLabel}];\n",
248 (x+1), (y+1), (z+1));
251 fprintf(nb, "If[AnimationPlot,{Do[tile%i%i%i[T]=Show[TILES%i%i%i, Background -> RGBColor[.93, .91, .89], ",
252 (x+1), (y+1), (z+1), (x+1), (y+1), (z+1));
253 fprintf(nb, "ViewPoint -> {1-(.99 T/frames)^2, T/(4 frames), 2 (T/frames)^2},ImageSize->AnimationSize], {T, 0, frames, 1}],\n");
254 fprintf(nb, "Do[tile%i%i%i[frames+T]=Show[TILES%i%i%i, Background -> RGBColor[.93, .91, .89], ViewPoint -> {.005+(T/frames)^2, ",
255 (x+1), (y+1), (z+1), (x+1), (y+1), (z+1));
256 fprintf(nb, "0.25-T/(4 frames), 2-2 (.99 T/frames)^2},ImageSize->AnimationSize], {T, 0, frames, 1}]}];\n");
261 fprintf(nb, "Image Export (x%i,x%i,x%i)", (x+1), (y+1), (z+1));
264 fprintf(nb, "If[AnimationPlot, images%i%i%i = Evaluate[Table[tile%i%i%i[j], {j, 0, 2 frames, 1}]]];\n",
265 (x+1), (y+1), (z+1), (x+1), (y+1), (z+1));
268 fprintf(nb, "Export[StillName<>\"%i%i%i\"<>\".\"<>ToLowerCase[StillType], still%i%i%i, StillType, ImageSize->StillSize, ",
269 (x+1), (y+1), (z+1), (x+1), (y+1), (z+1));
270 fprintf(nb, "ConversionOptions->{\"ColorReductionDither\" -> False}]");
273 fprintf(nb, "If[AnimationPlot, Export[AnimationName<>\"%i%i%i\"<>\".gif\", images%i%i%i, \"GIF\", ImageSize -> AnimationSize, ",
274 (x+1), (y+1), (z+1), (x+1), (y+1), (z+1));
275 fprintf(nb, "ConversionOptions -> {\"Loop\" -> True,\"AnimationDisplayTime\" -> FrameTime, ");
276 fprintf(nb, "\"ColorReductionDither\" -> False}]]");
280 }
281 }
282 }
284 fclose(nb);
285 RETURN(stat);
286}/* END - LALMathNDPlot() */
#define INSTRUCTIONS
Definition: LALMathNDPlot.c:37
#define ABORT(statusptr, code, mesg)
#define INITSTATUS(statusptr)
#define RETURN(statusptr)
#define fprintf
int32_t INT4
Four-byte signed integer.
float REAL4
Single precision real floating-point number (4 bytes).
#define BEG_TITLECELL
#define END_GROUPCELLC
#define LALMATHEMATICAH_EVAL
Invalid parameter value.
#define LALMATHEMATICAH_EFILE
Could not open file to write a Mathematica Notebook.
#define END_NOTEBOOK
#define BEG_TEXTCELL
#define BEG_GROUPCELL
#define BEG_SECTIONCELL
#define END_TEXTCELL_
#define END_GROUPCELLC_
#define BEG_NOTEBOOK
#define LALMATHEMATICAH_ENULL
NULL pointer to a LALMathematica.h input structure.
#define END_TITLECELL
#define BEG_INPUTCELL
void LALMathNDPlot(LALStatus *status, MathNDPointList *first, INT4 *ntiles, REAL4 *pointSize)
This function is for plotting N-Dimensional template banks by creating a MATHEMATICA notebook.
Definition: LALMathNDPlot.c:66
#define END_TEXTCELL
#define END_INPUTCELL_
#define END_SECTIONCELL
#define END_INPUTCELL
#define LALFopen
Definition: LALStdio.h:50
LAL status structure, see The LALStatus structure for more details.
Definition: LALDatatypes.h:947
This type is similar to Math3DPointList except the coordinates are stored as data in the REAL4Vector ...
REAL4Vector * coordinates
struct tagMathNDPointList * next
REAL4 * data
Pointer to the data array.
Definition: LALDatatypes.h:150
UINT4 length
Number of elements in array.
Definition: LALDatatypes.h:149