"under the hood" handle of Ambient File, Octree (oconv) and ray tracing for a C++ program

Hello all,

I am experimenting with Radiance code, with the purpose of creating a
calculation engine for Groundhog.

In the process, I have managed to write a C++ program (early tests have
passed, so far) that can read SketchUp model and export it in Radiance
format. However, my intention is to allow it to calculate things, thus
avoiding the need of exporting and handling thousands of files and
scripting.

My idea is to generate a program that basically receives a SketchUp model
and perform several calculations... a very simple call

gh_calc_engine Model.skp > results.txt

The program will need, of course, to create the octree (not from a text
file, but from the internal data structure) and run rtrace or something
like that. I am checking how to do it and haven't gotten very far... could
you guys help me?

For what I understand, a program would need some sort of structure as shown
below my signature, but I am unsure. I am far from compiling.... for now, I
am trying to understand how Radiance works underneath.

Your help/hints and other things will be very appreciated

Kind regards,

Germán

/* Groundhog RTRACE analog */

/* START */
extern CUBE thesene = {{0.0, 0.0, 0.0}, 0.0, EMPTY}; // Define "the scene"
extern OBJECT nsceneobjs; // number of objects
... // some more externs such as raynum, nrays, etc. present in
"src/rt/ray.h"

/* OCONV */

for (size_t i=0; i < nobjects; i++){
// THIS WILL BE DONE WITH MATERIALS AS WELL

// as shown in getobject function in readobj.c
if(obj = newobject() == OVOID)
error("Out of space")
objp = objptr(obj);

// translate
groundhog_object = objects[i];
objp->omod = groundhog_object.material.name; // this would be an int
objp->otype = groundhog_object.type;
objp->oname = groundhog_object.name;
groundhog_object.setRadianceArguments(&objp->oargs); // arguments are
validated by Groundhog

// insert
insertobject(obj);

}

/* RTRACE --- as seen in rt/rtmain.c*/
FVECT orig;
FVECT dir;
RAY thisray;
COLOR rayvalue;
marksources();
setambient();
for(size_t i=0; i < nrays; i++){
origin= groundhog_rays[i].origin; // need to normalize
orig[0] = origin.getX();
orig[1] = origin.getY();
orig[2]= origin.getZ();

direction = groundhog_rays[i].direction; // need to normalize
dir[0] = direction.getX();
dir[1] = direction.getY();
dir[2]= direction.getZ();

// Set up and trace rays … as in rtcompute
rayorigin(&thisray,PRIMARY,NULL,NULL);
if (imm_irrad) { // What does this do? acts like the +i param in RTRACE?
VSUM(thisray.rorg, org, dir, 1.1e-4);
thisray.rdir[0] = -dir[0];
thisray.rdir[1] = -dir[1];
thisray.rdir[2] = -dir[2];
thisray.rmax = 0.0;
thisray.revf = rayirrad;
} else {
VCOPY(thisray.rorg, org);
VCOPY(thisray.rdir, dir);
thisray.rmax = dmax;
if (castonly)
thisray.revf = raycast;
}
// Get value
rayvalue(&thisray); // not sure what this does
rayvalue = thisray.rcol; // Will this give me the RGB values to convert
into Lux or whatever?
// Sync ambient
ambsync(); // How do I initialize this ambient file???
}

Hi Germán,

Unless you really like making work for yourself, I wouldn't recommend eliminating oconv by building everything in memory. You wouldn't save yourself much time (if any) in the end, and you would end up using a lot more memory that way, as the process of writing out and reloading the octree cleans up the set lists and other structures.

You can still run oconv from your program, and even pass it scene data via a pipe using popen() or similar. I would then avail myself of the routines in src/rt/raycalls.c which are designed for your kind of code. You can call the "ray_init(char*)" function, passing it the name of your octree file, and it takes care of all the set-up details for you. The call "ray_trace(RAY*)" performs ray evaluation, and all the various command-line settings are available as global variables for your amusement.

Cheers,
-Greg

···

From: Germán Molina Larrain <[email protected]>
Date: September 13, 2017 2:57:17 PM PDT

Hello all,

I am experimenting with Radiance code, with the purpose of creating a calculation engine for Groundhog.

In the process, I have managed to write a C++ program (early tests have passed, so far) that can read SketchUp model and export it in Radiance format. However, my intention is to allow it to calculate things, thus avoiding the need of exporting and handling thousands of files and scripting.

My idea is to generate a program that basically receives a SketchUp model and perform several calculations... a very simple call

gh_calc_engine Model.skp > results.txt

The program will need, of course, to create the octree (not from a text file, but from the internal data structure) and run rtrace or something like that. I am checking how to do it and haven't gotten very far... could you guys help me?

For what I understand, a program would need some sort of structure as shown below my signature, but I am unsure. I am far from compiling.... for now, I am trying to understand how Radiance works underneath.

Your help/hints and other things will be very appreciated

Kind regards,

Germán

Hello Greg!

That sounds great. A while ago I tried to I the files you mentioned, but
did not have much luck. Today, with more knowledge, I may be able to handle
them.

One question: in your approach, do I need to export everything? This
this... Do I need to write the .Rad and .Mat and .VF files?

Cheers

···

On Sep 14, 2017 00:30, "Gregory J. Ward" <[email protected]> wrote:

Hi Germán,

Unless you really like making work for yourself, I wouldn't recommend
eliminating oconv by building everything in memory. You wouldn't save
yourself much time (if any) in the end, and you would end up using a lot
more memory that way, as the process of writing out and reloading the
octree cleans up the set lists and other structures.

You can still run oconv from your program, and even pass it scene data via
a pipe using popen() or similar. I would then avail myself of the routines
in src/rt/raycalls.c which are designed for your kind of code. You can
call the "ray_init(char*)" function, passing it the name of your octree
file, and it takes care of all the set-up details for you. The call
"ray_trace(RAY*)" performs ray evaluation, and all the various command-line
settings are available as global variables for your amusement.

Cheers,
-Greg

*From: *Germán Molina Larrain <[email protected]>

*Date: *September 13, 2017 2:57:17 PM PDT

Hello all,

I am experimenting with Radiance code, with the purpose of creating a
calculation engine for Groundhog.

In the process, I have managed to write a C++ program (early tests have
passed, so far) that can read SketchUp model and export it in Radiance
format. However, my intention is to allow it to calculate things, thus
avoiding the need of exporting and handling thousands of files and
scripting.

My idea is to generate a program that basically receives a SketchUp model
and perform several calculations... a very simple call

gh_calc_engine Model.skp > results.txt

The program will need, of course, to create the octree (not from a text
file, but from the internal data structure) and run rtrace or something
like that. I am checking how to do it and haven't gotten very far... could
you guys help me?

For what I understand, a program would need some sort of structure as
shown below my signature, but I am unsure. I am far from compiling.... for
now, I am trying to understand how Radiance works underneath.

Your help/hints and other things will be very appreciated

Kind regards,

Germán

_______________________________________________
Radiance-dev mailing list
[email protected]
https://www.radiance-online.org/mailman/listinfo/radiance-dev

One final question (learning to program in C++ here!): Should I compile
raycalls.c as a Library?

Best,

···

2017-09-14 8:16 GMT-03:00 Germán Molina Larrain <[email protected]>:

Hello Greg!

That sounds great. A while ago I tried to I the files you mentioned, but
did not have much luck. Today, with more knowledge, I may be able to handle
them.

One question: in your approach, do I need to export everything? This
this... Do I need to write the .Rad and .Mat and .VF files?

Cheers

On Sep 14, 2017 00:30, "Gregory J. Ward" <[email protected]> wrote:

Hi Germán,

Unless you really like making work for yourself, I wouldn't recommend
eliminating oconv by building everything in memory. You wouldn't save
yourself much time (if any) in the end, and you would end up using a lot
more memory that way, as the process of writing out and reloading the
octree cleans up the set lists and other structures.

You can still run oconv from your program, and even pass it scene data
via a pipe using popen() or similar. I would then avail myself of the
routines in src/rt/raycalls.c which are designed for your kind of code.
You can call the "ray_init(char*)" function, passing it the name of your
octree file, and it takes care of all the set-up details for you. The call
"ray_trace(RAY*)" performs ray evaluation, and all the various command-line
settings are available as global variables for your amusement.

Cheers,
-Greg

*From: *Germán Molina Larrain <[email protected]>

*Date: *September 13, 2017 2:57:17 PM PDT

Hello all,

I am experimenting with Radiance code, with the purpose of creating a
calculation engine for Groundhog.

In the process, I have managed to write a C++ program (early tests have
passed, so far) that can read SketchUp model and export it in Radiance
format. However, my intention is to allow it to calculate things, thus
avoiding the need of exporting and handling thousands of files and
scripting.

My idea is to generate a program that basically receives a SketchUp model
and perform several calculations... a very simple call

gh_calc_engine Model.skp > results.txt

The program will need, of course, to create the octree (not from a text
file, but from the internal data structure) and run rtrace or something
like that. I am checking how to do it and haven't gotten very far... could
you guys help me?

For what I understand, a program would need some sort of structure as
shown below my signature, but I am unsure. I am far from compiling.... for
now, I am trying to understand how Radiance works underneath.

Your help/hints and other things will be very appreciated

Kind regards,

Germán

_______________________________________________
Radiance-dev mailing list
[email protected]
https://www.radiance-online.org/mailman/listinfo/radiance-dev

Hi Germán,

As I said, you can pipe the materials and geometry to the oconv command, something like:

  FILE *outfp = popen("oconv - > /tmp/myfile.oct", "w");
  /* tons of stuff to outfp */
  pclose(outfp);
  ray_init("/tmp/myfile.oct");
  /* lots of calls to ray_trace() */
  ray_done();

Lots of other things to do as well, such as setting rendering options and error-checking. This should give you the basic idea, though.

Cheers,
-Greg

···

From: Germán Molina Larrain <[email protected]>
Date: September 14, 2017 4:16:56 AM PDT

Hello Greg!

That sounds great. A while ago I tried to I the files you mentioned, but did not have much luck. Today, with more knowledge, I may be able to handle them.

One question: in your approach, do I need to export everything? This this... Do I need to write the .Rad and .Mat and .VF files?

Cheers

On Sep 14, 2017 00:30, "Gregory J. Ward" <[email protected]> wrote:
Hi Germán,

Unless you really like making work for yourself, I wouldn't recommend eliminating oconv by building everything in memory. You wouldn't save yourself much time (if any) in the end, and you would end up using a lot more memory that way, as the process of writing out and reloading the octree cleans up the set lists and other structures.

You can still run oconv from your program, and even pass it scene data via a pipe using popen() or similar. I would then avail myself of the routines in src/rt/raycalls.c which are designed for your kind of code. You can call the "ray_init(char*)" function, passing it the name of your octree file, and it takes care of all the set-up details for you. The call "ray_trace(RAY*)" performs ray evaluation, and all the various command-line settings are available as global variables for your amusement.

Cheers,
-Greg

From: Germán Molina Larrain <[email protected]>
Date: September 13, 2017 2:57:17 PM PDT

Hello all,

I am experimenting with Radiance code, with the purpose of creating a calculation engine for Groundhog.

In the process, I have managed to write a C++ program (early tests have passed, so far) that can read SketchUp model and export it in Radiance format. However, my intention is to allow it to calculate things, thus avoiding the need of exporting and handling thousands of files and scripting.

My idea is to generate a program that basically receives a SketchUp model and perform several calculations... a very simple call

gh_calc_engine Model.skp > results.txt

The program will need, of course, to create the octree (not from a text file, but from the internal data structure) and run rtrace or something like that. I am checking how to do it and haven't gotten very far... could you guys help me?

For what I understand, a program would need some sort of structure as shown below my signature, but I am unsure. I am far from compiling.... for now, I am trying to understand how Radiance works underneath.

Your help/hints and other things will be very appreciated

Kind regards,

Germán

It's already compiled during Radiance build in the separate library "libraycalls.a". You'll need to link to the libraries in src/lib, including:

  -lraycalls -lradiance -lrtrad

The "libradiance.a" library contains all the rendering routines, and "librtrad.a", built in the src/common directory, contains a bunch of common routines used by Radiance tools.

-Greg

···

From: Germán Molina Larrain <[email protected]>
Date: September 14, 2017 7:22:32 AM PDT

One final question (learning to program in C++ here!): Should I compile raycalls.c as a Library?

Best,

2017-09-14 8:16 GMT-03:00 Germán Molina Larrain <[email protected]>:
Hello Greg!

That sounds great. A while ago I tried to I the files you mentioned, but did not have much luck. Today, with more knowledge, I may be able to handle them.

One question: in your approach, do I need to export everything? This this... Do I need to write the .Rad and .Mat and .VF files?

Cheers

On Sep 14, 2017 00:30, "Gregory J. Ward" <[email protected]> wrote:
Hi Germán,

Unless you really like making work for yourself, I wouldn't recommend eliminating oconv by building everything in memory. You wouldn't save yourself much time (if any) in the end, and you would end up using a lot more memory that way, as the process of writing out and reloading the octree cleans up the set lists and other structures.

You can still run oconv from your program, and even pass it scene data via a pipe using popen() or similar. I would then avail myself of the routines in src/rt/raycalls.c which are designed for your kind of code. You can call the "ray_init(char*)" function, passing it the name of your octree file, and it takes care of all the set-up details for you. The call "ray_trace(RAY*)" performs ray evaluation, and all the various command-line settings are available as global variables for your amusement.

Cheers,
-Greg

From: Germán Molina Larrain <[email protected]>
Date: September 13, 2017 2:57:17 PM PDT

Hello all,

I am experimenting with Radiance code, with the purpose of creating a calculation engine for Groundhog.

In the process, I have managed to write a C++ program (early tests have passed, so far) that can read SketchUp model and export it in Radiance format. However, my intention is to allow it to calculate things, thus avoiding the need of exporting and handling thousands of files and scripting.

My idea is to generate a program that basically receives a SketchUp model and perform several calculations... a very simple call

gh_calc_engine Model.skp > results.txt

The program will need, of course, to create the octree (not from a text file, but from the internal data structure) and run rtrace or something like that. I am checking how to do it and haven't gotten very far... could you guys help me?

For what I understand, a program would need some sort of structure as shown below my signature, but I am unsure. I am far from compiling.... for now, I am trying to understand how Radiance works underneath.

Your help/hints and other things will be very appreciated

Kind regards,

Germán

_______________________________________________
Radiance-dev mailing list
[email protected]
https://www.radiance-online.org/mailman/listinfo/radiance-dev

_______________________________________________
Radiance-dev mailing list
[email protected]
https://www.radiance-online.org/mailman/listinfo/radiance-dev

Great! I will give that a try. Thanks very much!

···

2017-09-14 12:43 GMT-03:00 Gregory J. Ward <[email protected]>:

Hi Germán,

As I said, you can pipe the materials and geometry to the oconv command,
something like:

FILE *outfp = popen("oconv - > /tmp/myfile.oct", "w");
/* tons of stuff to outfp */
pclose(outfp);
ray_init("/tmp/myfile.oct");
/* lots of calls to ray_trace() */
ray_done();

Lots of other things to do as well, such as setting rendering options and
error-checking. This should give you the basic idea, though.

Cheers,
-Greg

*From: *Germán Molina Larrain <[email protected]>

*Date: *September 14, 2017 4:16:56 AM PDT

Hello Greg!

That sounds great. A while ago I tried to I the files you mentioned, but
did not have much luck. Today, with more knowledge, I may be able to handle
them.

One question: in your approach, do I need to export everything? This
this... Do I need to write the .Rad and .Mat and .VF files?

Cheers

On Sep 14, 2017 00:30, "Gregory J. Ward" <[email protected]> wrote:

Hi Germán,

Unless you really like making work for yourself, I wouldn't recommend
eliminating oconv by building everything in memory. You wouldn't save
yourself much time (if any) in the end, and you would end up using a lot
more memory that way, as the process of writing out and reloading the
octree cleans up the set lists and other structures.

You can still run oconv from your program, and even pass it scene data
via a pipe using popen() or similar. I would then avail myself of the
routines in src/rt/raycalls.c which are designed for your kind of code.
You can call the "ray_init(char*)" function, passing it the name of your
octree file, and it takes care of all the set-up details for you. The call
"ray_trace(RAY*)" performs ray evaluation, and all the various command-line
settings are available as global variables for your amusement.

Cheers,
-Greg

*From: *Germán Molina Larrain <[email protected]>

*Date: *September 13, 2017 2:57:17 PM PDT

Hello all,

I am experimenting with Radiance code, with the purpose of creating a
calculation engine for Groundhog.

In the process, I have managed to write a C++ program (early tests have
passed, so far) that can read SketchUp model and export it in Radiance
format. However, my intention is to allow it to calculate things, thus
avoiding the need of exporting and handling thousands of files and
scripting.

My idea is to generate a program that basically receives a SketchUp model
and perform several calculations... a very simple call

gh_calc_engine Model.skp > results.txt

The program will need, of course, to create the octree (not from a text
file, but from the internal data structure) and run rtrace or something
like that. I am checking how to do it and haven't gotten very far... could
you guys help me?

For what I understand, a program would need some sort of structure as
shown below my signature, but I am unsure. I am far from compiling.... for
now, I am trying to understand how Radiance works underneath.

Your help/hints and other things will be very appreciated

Kind regards,

Germán

_______________________________________________
Radiance-dev mailing list
[email protected]
https://www.radiance-online.org/mailman/listinfo/radiance-dev