Fixed it

On Sun, Mar 20, 2016 at 6:47 AM Vasco Alexandre da Silva Costa <
vasco.co...@gmail.com> wrote:

> It doesn't compile. It seems you forgot a function declaration in a header
> file:
>
> .../brlcad/trunk/src/librt/primitives/primitive_util.c: In function
> ‘clt_solid_pack’:
> .../brlcad/trunk/src/librt/primitives/primitive_util.c:648:25: error:
> implicit declaration of function ‘clt_epa_pack’
> [-Werror=implicit-function-declaration]
>   case ID_EPA:    size = clt_epa_pack(pool, stp); break;
>                          ^
>
>
> On Sat, Mar 19, 2016 at 1:03 PM, Param Hanji <param.catchch...@gmail.com>
> wrote:
>
>> Here's the new patch.
>>
>>
>> On Sat, Mar 19, 2016 at 6:32 PM Param Hanji <param.catchch...@gmail.com>
>> wrote:
>>
>>> Oops I did manually edit the patch. I ran diff again and uploaded the
>>> patch without changes. I also changed the ID used to 19.
>>>
>>> On Sat 19 Mar, 2016, 2:51 AM Vasco Alexandre da Silva Costa, <
>>> vasco.co...@gmail.com> wrote:
>>>
>>>> On Fri, Mar 18, 2016 at 9:14 PM, Vasco Alexandre da Silva Costa <
>>>> vasco.co...@gmail.com> wrote:
>>>>
>>>>> On Fri, Mar 18, 2016 at 1:17 PM, Param Hanji <
>>>>> param.catchch...@gmail.com> wrote:
>>>>>
>>>>>> Hello,
>>>>>>
>>>>>> On Thu, Mar 17, 2016 at 4:57 AM Vasco Alexandre da Silva Costa <
>>>>>> vasco.co...@gmail.com> wrote:
>>>>>>
>>>>>>> On Wed, Mar 16, 2016 at 9:44 PM, Param Hanji <
>>>>>>> param.catchch...@gmail.com> wrote:
>>>>>>>
>>>>>>> You will need a lot of time to port bool.c so you need to schedule
>>>>>>> appropriately. That code is rife with gotos, structs with pointers, and
>>>>>>> dynamic memory allocation. We don't want any of that in OpenCL. The 
>>>>>>> sooner
>>>>>>> you start looking into that code the better. I did some patches last 
>>>>>>> summer
>>>>>>> to remove many gotos from the existing code but there are still several
>>>>>>> left.
>>>>>>>
>>>>>>> I suggest you read the presentation Sean linked to so you can get an
>>>>>>> idea for what boolean operations and CSG are:
>>>>>>> http://web.iitd.ac.in/~hegde/cad/lecture/L30_solidmod_basics.pdf
>>>>>>>
>>>>>>> The main functions of interest in bool.c are rt_bool_eval,
>>>>>>> rt_boolweave, and rt_boolfinal. rt_boolweave and rt_bool_final do 
>>>>>>> dynamic
>>>>>>> memory allocations with linked lists but, if you read their code 
>>>>>>> carefully,
>>>>>>> the maximum output size is bounded as a function of the input size. The
>>>>>>> input is the list of intersection points. The size of the list of
>>>>>>> intersection points is already being computed by rt.cl:count_hits().
>>>>>>> So you can pre allocate a chunk of memory with the maximum possible 
>>>>>>> output
>>>>>>> size and pass that array to your functions.
>>>>>>> As for rt_bool_eval the boolean ops tree is stored as a tree of
>>>>>>> pointers to structs. Can't have that. The rt_bool_eval function uses 
>>>>>>> gotos.
>>>>>>> Can't have those either.
>>>>>>>
>>>>>>
>>>>>> I'll start looking into the code as soon as i can. Is there any
>>>>>> resource I can refer to get a brief high level understanding of how ray
>>>>>> tracing occurs. I have no knowledge of computer graphics and even
>>>>>> theoretical resources pertaining to the specific functions(eval, weave)
>>>>>> would be helpful. I'll look out for some on my own too.
>>>>>>
>>>>>
>>>>> If you want a brief idea of how the ray-tracing algorithm works you
>>>>> can look at the relevant Wikipedia page. Wikipedia is a decent resource 
>>>>> for
>>>>> basic computer graphics knowledge:
>>>>> https://en.wikipedia.org/wiki/Ray_tracing_%28graphics%29
>>>>>
>>>>> For knowing how CSG works, including the boolean ops, that lecture PDF
>>>>> is a good resource.
>>>>>
>>>>>
>>>>>> I started a patch in ANSI C to reimplement rt_bool_eval without gotos
>>>>>> with a linearized tree, stored in an array, which can be easily copied to
>>>>>> the compute device. You can find that patch here:
>>>>>> https://sourceforge.net/p/brlcad/patches/417/
>>>>>>
>>>>>>> The rt_bool_eval patch #417 is functional but it still has some
>>>>>>> warts in it.
>>>>>>>
>>>>>>>
>>>>>> I noticed that you had proposed to design a new implementation of the
>>>>>> boolean weave function in this pdf last year.
>>>>>>
>>>>>> https://drive.google.com/file/d/0B85Rkmt7rnCTZV9HNVIyZTRUMWM/view
>>>>>>
>>>>>> Was this discarded entirely? If not, does it make sense to change the
>>>>>> way weave is performed currently to facilitate easy portability to 
>>>>>> OpenCL?
>>>>>> Or should I just go about porting the existing code?
>>>>>>
>>>>>
>>>>> That PDF you linked to is from a pre-proposal which was later changed
>>>>> with output from Sean and the others. Eventually it was decided that we
>>>>> would start with a first hit ray tracer and later on work on the boolean
>>>>> evaluation proper to get working CSG. It just turns out that there was too
>>>>> much effort involved in getting the object partitioning and the rendering
>>>>> pipeline up to speed. Not to mention all those primitives... So I couldn't
>>>>> finish work on boolean evaluation before the GSoC period ended. I just did
>>>>> some cleanups (e.g. goto removal) on bool.c.
>>>>>
>>>>> Which is a good thing too or there would be little left to work on for
>>>>> this GSoC. :-)
>>>>>
>>>>> Just ignore that PDF you got from Google Drive, which is something I
>>>>> wrote before the GSoC 2015 period started, and read the advice I gave you
>>>>> about how to tackle bool.c in this maling-list which includes the 
>>>>> knowledge
>>>>> I have now. I described a possible approach in detail here. I also said
>>>>> which functions were most important (rt_bool_eval, rt_boolweave,
>>>>> rt_bool_final)
>>>>>
>>>>
>>>> PS: That project timeline in the PDF was shot down and I had to revise
>>>> it. There was too much time doing research in it and not enough time
>>>> actually coding. At the time I was unsure if the current bool weave
>>>> algorithm BRL-CAD uses would make sense on a GPU or not. It turns out it
>>>> does make sense but its like I said: you have to remove all the gotos,
>>>> remove all pointers inside data structures, figure out the bounds of the
>>>> memory you need a priori, and rethink the algorithm from those dynamic
>>>> linked lists to a priori bounded arrays.
>>>>
>>>> --
>>>> Vasco Alexandre da Silva Costa
>>>> PhD in Computer Engineering (Computer Graphics)
>>>> Instituto Superior Técnico/University of Lisbon, Portugal
>>>>
>>>> ------------------------------------------------------------------------------
>>>> Transform Data into Opportunity.
>>>> Accelerate data analysis in your applications with
>>>> Intel Data Analytics Acceleration Library.
>>>> Click to learn more.
>>>> http://pubads.g.doubleclick.net/gampad/clk?id=278785231&iu=/4140
>>>> _______________________________________________
>>>> BRL-CAD Developer mailing list
>>>> brlcad-devel@lists.sourceforge.net
>>>> https://lists.sourceforge.net/lists/listinfo/brlcad-devel
>>>>
>>>
>>
>> ------------------------------------------------------------------------------
>> Transform Data into Opportunity.
>> Accelerate data analysis in your applications with
>> Intel Data Analytics Acceleration Library.
>> Click to learn more.
>> http://pubads.g.doubleclick.net/gampad/clk?id=278785231&iu=/4140
>> _______________________________________________
>> BRL-CAD Developer mailing list
>> brlcad-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/brlcad-devel
>>
>>
>
>
> --
> Vasco Alexandre da Silva Costa
> PhD in Computer Engineering (Computer Graphics)
> Instituto Superior Técnico/University of Lisbon, Portugal
>
> ------------------------------------------------------------------------------
> Transform Data into Opportunity.
> Accelerate data analysis in your applications with
> Intel Data Analytics Acceleration Library.
> Click to learn more.
> http://pubads.g.doubleclick.net/gampad/clk?id=278785231&iu=/4140
> _______________________________________________
> BRL-CAD Developer mailing list
> brlcad-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/brlcad-devel
>
diff -Nurd brlcad-master/src/librt/librt_private.h brlcad-branch/src/librt/librt_private.h
--- brlcad-master/src/librt/librt_private.h	2016-03-19 08:29:47.574128546 +0530
+++ brlcad-branch/src/librt/librt_private.h	2016-03-19 18:04:13.440772786 +0530
@@ -194,6 +194,7 @@
 CLT_DECLARE_INTERFACE(sph);
 CLT_DECLARE_INTERFACE(ehy);
 CLT_DECLARE_INTERFACE(bot);
+CLT_DECLARE_INTERFACE(epa);
 
 extern size_t clt_bot_pack(struct bu_pool *pool, struct soltab *stp);
 #endif
diff -Nurd brlcad-master/src/librt/primitives/common.cl brlcad-branch/src/librt/primitives/common.cl
--- brlcad-master/src/librt/primitives/common.cl	2016-03-19 08:29:46.034128528 +0530
+++ brlcad-branch/src/librt/primitives/common.cl	2016-03-19 17:50:37.532763138 +0530
@@ -114,6 +114,7 @@
 struct arb_specific;
 struct ehy_specific;
 struct ell_specific;
+struct epa_specific;
 struct rec_specific;
 struct sph_specific;
 struct tgc_specific;
@@ -123,6 +124,7 @@
 extern int bot_shot(RESULT_TYPE *res, const double3 r_pt, double3 r_dir, const uint idx, global const uchar *args);
 extern int ehy_shot(RESULT_TYPE *res, const double3 r_pt, const double3 r_dir, const uint idx, global const struct ehy_specific *ehy);
 extern int ell_shot(RESULT_TYPE *res, const double3 r_pt, const double3 r_dir, const uint idx, global const struct ell_specific *ell);
+extern int epa_shot(RESULT_TYPE *res, const double3 r_pt, const double3 r_dir, const uint idx, global const struct epa_specific *epa);
 extern int rec_shot(RESULT_TYPE *res, const double3 r_pt, const double3 r_dir, const uint idx, global const struct rec_specific *rec);
 extern int sph_shot(RESULT_TYPE *res, const double3 r_pt, const double3 r_dir, const uint idx, global const struct sph_specific *sph);
 extern int tgc_shot(RESULT_TYPE *res, const double3 r_pt, const double3 r_dir, const uint idx, global const struct tgc_specific *tgc);
@@ -132,6 +134,7 @@
 extern void bot_norm(struct hit *hitp, const double3 r_pt, const double3 r_dir, global const uchar *args);
 extern void ehy_norm(struct hit *hitp, const double3 r_pt, const double3 r_dir, global const struct ehy_specific *ehy);
 extern void ell_norm(struct hit *hitp, const double3 r_pt, const double3 r_dir, global const struct ell_specific *ell);
+extern void epa_norm(struct hit *hitp, const double3 r_pt, const double3 r_dir, global const struct epa_specific *epa);
 extern void rec_norm(struct hit *hitp, const double3 r_pt, const double3 r_dir, global const struct rec_specific *rec);
 extern void sph_norm(struct hit *hitp, const double3 r_pt, const double3 r_dir, global const struct sph_specific *sph);
 extern void tgc_norm(struct hit *hitp, const double3 r_pt, const double3 r_dir, global const struct tgc_specific *tgc);
diff -Nurd brlcad-master/src/librt/primitives/epa/epa.c brlcad-branch/src/librt/primitives/epa/epa.c
--- brlcad-master/src/librt/primitives/epa/epa.c	2016-03-19 08:29:47.454128545 +0530
+++ brlcad-branch/src/librt/primitives/epa/epa.c	2016-03-19 17:42:50.280757612 +0530
@@ -184,6 +184,37 @@
     { {'\0', '\0', '\0', '\0'}, 0, (char *)NULL, 0, BU_STRUCTPARSE_FUNC_NULL, NULL, NULL }
 };
 
+
+#ifdef USE_OPENCL
+/* largest data members first */
+struct clt_epa_specific {
+    cl_double epa_V[3];     /* vector to epa origin */
+    cl_double epa_Hunit[3]; /* unit H vector */
+    cl_double epa_SoR[16];  /* Scale(Rot(vect)) */
+    cl_double epa_invRoS[16];   /* invRot(Scale(vect)) */
+};
+
+size_t
+clt_epa_pack(struct bu_pool *pool, struct soltab *stp)
+{
+    struct epa_specific *epa =
+        (struct epa_specific *)stp->st_specific;
+    struct clt_epa_specific *args;
+
+    const size_t size = sizeof(*args);
+    args = (struct clt_epa_specific*)bu_pool_alloc(pool, 1, size);
+
+    VMOVE(args->epa_V, epa->epa_V);
+    VMOVE(args->epa_Hunit, epa->epa_Hunit);
+    MAT_COPY(args->epa_SoR, epa->epa_SoR);
+    MAT_COPY(args->epa_invRoS, epa->epa_invRoS);
+printf("Success\n");
+    return size;
+}
+
+#endif /* USE_OPENCL */
+
+
 /**
  * Create a bounding RPP for an epa
  */
diff -Nurd brlcad-master/src/librt/primitives/epa/epa_shot.cl brlcad-branch/src/librt/primitives/epa/epa_shot.cl
--- brlcad-master/src/librt/primitives/epa/epa_shot.cl	1970-01-01 05:30:00.000000000 +0530
+++ brlcad-branch/src/librt/primitives/epa/epa_shot.cl	2016-03-17 14:42:48.659727000 +0530
@@ -0,0 +1,142 @@
+#include "common.cl"
+
+
+/* hit_surfno is set to one of these */
+#define EPA_NORM_BODY	(1)		/* compute normal */
+#define EPA_NORM_TOP	(2)		/* copy epa_N */
+
+
+struct epa_specific {
+    double epa_V[3];		// vector to epa origin
+    double epa_Hunit[3];	// unit H vector
+    double epa_SoR[16];		// Scale(Rot(vect))
+    double epa_invRoS[16];	// invRot(Scale(vect))
+};
+
+int epa_shot(RESULT_TYPE *res, const double3 r_pt, const double3 r_dir, const uint idx, global const struct epa_specific *epa)
+{
+	double3 dp;			// D'
+    double3 pp;			// P'
+    double k1, k2;		// distance constants of solution
+    double3 xlated;		// translated vector
+    struct hit hits[2];	// 2 potential hit points
+    struct hit *hitp;	// pointer to hit point
+
+    dp = MAT4X3VEC(epa->epa_SoR, r_dir);
+    xlated = r_pt - vload3(0, epa->epa_V);
+    pp = MAT4X3VEC(epa->epa_SoR, xlated);
+
+    // Find roots of the equation
+    double a, b, c;		//coeffs of polynomial
+	double disc;		// disc of radical
+
+    hitp = &hits[0];
+
+	a = dp.x * dp.x + dp.y * dp.y;
+	b = 2 * (dp.x * pp.x + dp.y * pp.y)
+	    - dp.z;
+	c = pp.x * pp.x
+	    + pp.y * pp.y - pp.z - 1.0;
+	if (!NEAR_ZERO(a, RT_PCOEF_TOL)) {
+	    disc = b*b - 4 * a * c;
+	    if (disc > 0.0) {
+		    disc = sqrt(disc);
+
+		    k1 = (-b + disc) / (2.0 * a);
+		    k2 = (-b - disc) / (2.0 * a);
+
+		    /* k1 and k2 are potential solutions to intersection with
+		     * side.  See if they fall in range.
+		     */
+		    hitp->hit_vpriv = pp + k1 * dp;		// hit'
+		    if (hitp->hit_vpriv.z <= 0.0) {
+				hitp->hit_dist = k1;
+				hitp->hit_surfno = EPA_NORM_BODY;	// compute N
+				hitp++;
+		    }
+
+		    hitp->hit_vpriv = pp + k2 * dp;		// hit'
+		    if (hitp->hit_vpriv.z <= 0.0) {
+				hitp->hit_dist = k2;
+				hitp->hit_surfno = EPA_NORM_BODY;	// compute N
+				hitp++;
+			}
+		}
+	} else if (!NEAR_ZERO(b, RT_PCOEF_TOL)) {
+	    k1 = -c/b;
+	    hitp->hit_vpriv = pp + k1 * dp;		// hit'
+	    if (hitp->hit_vpriv.z <= 0.0) {
+			hitp->hit_dist = k1;
+			hitp->hit_surfno = EPA_NORM_BODY;	// compute N
+			hitp++;
+	    }
+	}
+
+	/*
+     * Check for hitting the top plate.
+     */
+    /* check top plate */
+    if (hitp == &hits[1]  &&  !ZERO(dp.z)) {
+		// 1 hit so far, this is worthwhile
+		k1 = -pp.z / dp.z;		// top plate
+		hitp->hit_vpriv = pp + k1 * dp;		//hit'
+		if (hitp->hit_vpriv.x * hitp->hit_vpriv.x +
+		    hitp->hit_vpriv.y * hitp->hit_vpriv.y <= 1.0) {
+		    hitp->hit_dist = k1;
+		    hitp->hit_surfno = EPA_NORM_TOP;	// -H
+		    hitp++;
+		}
+    }
+
+    if (hitp != &hits[2]) {
+        return 0;	// MISS
+    }
+
+    if (hits[0].hit_dist < hits[1].hit_dist) {
+		// entry is [0], exit is [1]
+	do_segp(res, idx, &hits[0], &hits[1]);
+    } else {
+	/* entry is [1], exit is [0] */
+	do_segp(res, idx, &hits[1], &hits[0]);
+    }
+    return 2;	// HIT
+}
+
+
+void epa_norm(struct hit *hitp, const double3 r_pt, const double3 r_dir, global const struct epa_specific *epa)
+{
+    double scale;
+    double3 can_normal;	// normal to canonical epa
+
+    hitp->hit_point = r_pt + r_dir * hitp->hit_dist;
+    switch (hitp->hit_surfno) {
+	case EPA_NORM_BODY:
+	    can_normal = (double3){
+		hitp->hit_vpriv.x,
+		hitp->hit_vpriv.y,
+	        -0.5};
+	    hitp->hit_normal = MAT4X3VEC(epa->epa_invRoS, can_normal);
+	    scale = 1.0 / length(hitp->hit_normal);
+	    hitp->hit_normal = hitp->hit_normal * scale;
+
+	    // tuck away this scale for the curvature routine
+	    hitp->hit_vpriv.x = scale;
+	    break;
+	case EPA_NORM_TOP:
+	    hitp->hit_normal = -vload3(0, epa->epa_Hunit);
+	    break;
+	default:
+	    break;
+    }
+}
+
+
+/*
+ * Local Variables:
+ * mode: C
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * c-file-style: "stroustrup"
+ * End:
+ * ex: shiftwidth=4 tabstop=8
+ */
diff -Nurd brlcad-master/src/librt/primitives/primitive_util.c brlcad-branch/src/librt/primitives/primitive_util.c
--- brlcad-master/src/librt/primitives/primitive_util.c	2016-03-19 08:29:45.138128517 +0530
+++ brlcad-branch/src/librt/primitives/primitive_util.c	2016-03-19 18:09:15.484776358 +0530
@@ -588,6 +588,7 @@
             "bot_shot.cl",
             "ehy_shot.cl",
             "ell_shot.cl",
+	    "epa_shot.cl",
             "sph_shot.cl",
             "rec_shot.cl",
             "tgc_shot.cl",
@@ -644,6 +645,7 @@
 	case ID_EHY:    size = clt_ehy_pack(pool, stp);	break;
 	case ID_ARS:
 	case ID_BOT:    size = clt_bot_pack(pool, stp);	break;
+	case ID_EPA:    size = clt_epa_pack(pool, stp);	break;
 	default:	size = 0;			break;
     }
     return size;
diff -Nurd brlcad-master/src/librt/primitives/rt.cl brlcad-branch/src/librt/primitives/rt.cl
--- brlcad-master/src/librt/primitives/rt.cl	2016-03-19 08:29:46.290128531 +0530
+++ brlcad-branch/src/librt/primitives/rt.cl	2016-03-19 17:48:54.608761920 +0530
@@ -89,6 +89,7 @@
 #define ID_ARS          5       /**< @brief ARS */
 #define ID_REC          7       /**< @brief Right Elliptical Cylinder [TGC special] */
 #define ID_SPH          10      /**< @brief Sphere */
+#define ID_EPA          19      /**< @brief Elliptical Paraboloid */
 #define ID_EHY          20      /**< @brief Elliptical Hyperboloid  */
 #define ID_BOT          30      /**< @brief Bag o' triangles */
 
@@ -105,6 +106,7 @@
     case ID_EHY:	return ehy_shot(res, r_pt, r_dir, idx, args);
     case ID_ARS:
     case ID_BOT:	return bot_shot(res, r_pt, r_dir, idx, args);
+    case ID_EPA:	return epa_shot(res, r_pt, r_dir, idx, args);
     default:		return 0;
     };
 }
@@ -121,6 +123,7 @@
     case ID_SPH:	sph_norm(hitp, r_pt, r_dir, args);	break;
     case ID_ARS:
     case ID_BOT:	bot_norm(hitp, r_pt, r_dir, args);	break;
+    case ID_EPA:	epa_norm(hitp, r_pt, r_dir, args);	break;
     default:							break;
     };
 }
------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785231&iu=/4140
_______________________________________________
BRL-CAD Developer mailing list
brlcad-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-devel

Reply via email to