void setKnownXi_ReduceSizeOfEQS(std::vector<IndexValue> &list_dirichlet_bc, MathLib::CRSMatrix< double, INDEX_TYPE> &eqsA, double* org_eqsRHS, double* org_eqsX, double** eqsRHS, double** eqsX, std::map<INDEX_TYPE, INDEX_TYPE> &map_solved_orgEqs) { const size_t n_org_rows = eqsA.getNRows(); std::vector<INDEX_TYPE> removed_rows(list_dirichlet_bc.size()); std::cout << "[BC] (transpose matrix) ... " << std::flush; RunTimeTimer run_trans; run_trans.start(); MathLib::CRSMatrix<double, INDEX_TYPE>* transpose_mat (eqsA.getTranspose()); run_trans.stop(); std::cout << run_trans.elapsed() << " s" << std::endl; INDEX_TYPE const*const row_ptr (transpose_mat->getRowPtrArray()); INDEX_TYPE const*const col_idx (transpose_mat->getColIdxArray()); double const*const data (transpose_mat->getEntryArray()); for (size_t i = 0; i < list_dirichlet_bc.size(); i++) { IndexValue &bc = list_dirichlet_bc.at(i); const size_t id = bc.id; const double val = bc.val; removed_rows.at(i) = id; //b_i -= A(i,k)*val, i!=k // for (size_t j = 0; j < eqsA.getNCols(); j++) // org_eqsRHS[j] -= eqsA.getValue(j, id) * val; const INDEX_TYPE end(row_ptr[id+1]); for (INDEX_TYPE k(row_ptr[id]); k<end; k++) { const INDEX_TYPE j(col_idx[k]); org_eqsRHS[j] -= data[j] * val; } //b_k = A_kk*val org_eqsRHS[id] = val; //=eqsA(id, id)*val; org_eqsX[id] = val; //=eqsA(id, id)*val; } delete transpose_mat; //remove rows and columns eqsA.eraseEntries(removed_rows.size(), &removed_rows[0]); //remove X,RHS (*eqsX) = new double[n_org_rows - removed_rows.size()]; (*eqsRHS) = new double[n_org_rows-removed_rows.size()]; size_t new_id = 0; for (size_t i=0; i<n_org_rows; i++) { if (std::find(removed_rows.begin(), removed_rows.end(), static_cast<unsigned>(i))!=removed_rows.end()) continue; (*eqsRHS)[new_id] = org_eqsRHS[i]; (*eqsX)[new_id] = org_eqsX[i]; map_solved_orgEqs[new_id] = i; new_id++; } }
GimpRGB get_ray_color_box (GimpVector3 *pos) { GimpVector3 lvp, ldir, vp, p, dir, ns, nn; GimpRGB color, color2; gfloat m[16]; gint i; FaceIntersectInfo face_intersect[2]; color = background; vp = mapvals.viewpoint; p = *pos; /* Translate viewpoint so that the box has its origin */ /* at its lower left corner. */ /* ================================================== */ vp.x = vp.x - mapvals.position.x; vp.y = vp.y - mapvals.position.y; vp.z = vp.z - mapvals.position.z; p.x = p.x - mapvals.position.x; p.y = p.y - mapvals.position.y; p.z = p.z - mapvals.position.z; /* Compute direction */ /* ================= */ gimp_vector3_sub (&dir, &p, &vp); gimp_vector3_normalize (&dir); /* Compute inverse of rotation matrix and apply it to */ /* the viewpoint and direction. This transforms the */ /* observer into the local coordinate system of the box */ /* ==================================================== */ memcpy (m, rotmat, sizeof (gfloat) * 16); transpose_mat (m); vecmulmat (&lvp, &vp, m); vecmulmat (&ldir, &dir, m); /* Ok. Now the observer is in the space where the box is located */ /* with its lower left corner at the origin and its axis aligned */ /* to the cartesian basis. Check if the transformed ray hits it. */ /* ============================================================= */ face_intersect[0].t = 1000000.0; face_intersect[1].t = 1000000.0; if (intersect_box (mapvals.scale, lvp, ldir, face_intersect) == TRUE) { /* We've hit the box. Transform the hit points and */ /* normals back into the world coordinate system */ /* =============================================== */ for (i = 0; i < 2; i++) { vecmulmat (&ns, &face_intersect[i].s, rotmat); vecmulmat (&nn, &face_intersect[i].n, rotmat); ns.x = ns.x + mapvals.position.x; ns.y = ns.y + mapvals.position.y; ns.z = ns.z + mapvals.position.z; face_intersect[i].s = ns; face_intersect[i].n = nn; } color = get_box_image_color (face_intersect[0].face, face_intersect[0].u, face_intersect[0].v); /* Check for total transparency... */ /* =============================== */ if (color.a < 1.0) { /* Hey, we can see through here! */ /* Lets see what's on the other side.. */ /* =================================== */ color = phong_shade (&face_intersect[0].s, &mapvals.viewpoint, &face_intersect[0].n, &mapvals.lightsource.position, &color, &mapvals.lightsource.color, mapvals.lightsource.type); gimp_rgb_clamp (&color); color2 = get_box_image_color (face_intersect[1].face, face_intersect[1].u, face_intersect[1].v); /* Make the normal point inwards */ /* ============================= */ gimp_vector3_mul (&face_intersect[1].n, -1.0); color2 = phong_shade (&face_intersect[1].s, &mapvals.viewpoint, &face_intersect[1].n, &mapvals.lightsource.position, &color2, &mapvals.lightsource.color, mapvals.lightsource.type); gimp_rgb_clamp (&color2); if (mapvals.transparent_background == FALSE && color2.a < 1.0) { gimp_rgb_composite (&color2, &background, GIMP_RGB_COMPOSITE_BEHIND); } /* Compute a mix of the first and second colors */ /* ============================================ */ gimp_rgb_composite (&color, &color2, GIMP_RGB_COMPOSITE_NORMAL); gimp_rgb_clamp (&color); } else if (color.a != 0.0 && mapvals.lightsource.type != NO_LIGHT) { color = phong_shade (&face_intersect[0].s, &mapvals.viewpoint, &face_intersect[0].n, &mapvals.lightsource.position, &color, &mapvals.lightsource.color, mapvals.lightsource.type); gimp_rgb_clamp (&color); } } else { if (mapvals.transparent_background == TRUE) gimp_rgb_set_alpha (&color, 0.0); } return color; }
static gboolean intersect_box (GimpVector3 scale, GimpVector3 viewp, GimpVector3 dir, FaceIntersectInfo *face_intersect) { GimpVector3 v, d, tmp, axis[3]; FaceIntersectInfo face_tmp; gboolean result = FALSE; gfloat m[16]; gint i = 0; gimp_vector3_set (&axis[0], 1.0, 0.0, 0.0); gimp_vector3_set (&axis[1], 0.0, 1.0, 0.0); gimp_vector3_set (&axis[2], 0.0, 0.0, 1.0); /* Front side */ /* ========== */ if (intersect_rect (scale.x, scale.y, scale.z / 2.0, viewp, dir, &face_intersect[i]) == TRUE) { face_intersect[i].face = 0; gimp_vector3_set (&face_intersect[i++].n, 0.0, 0.0, 1.0); result = TRUE; } /* Back side */ /* ========= */ if (intersect_rect (scale.x, scale.y, -scale.z / 2.0, viewp, dir, &face_intersect[i]) == TRUE) { face_intersect[i].face = 1; face_intersect[i].u = 1.0 - face_intersect[i].u; gimp_vector3_set (&face_intersect[i++].n, 0.0, 0.0, -1.0); result = TRUE; } /* Check if we've found the two possible intersection points */ /* ========================================================= */ if (i < 2) { /* Top: Rotate viewpoint and direction into rectangle's local coordinate system */ /* ============================================================================ */ rotatemat (90, &axis[0], m); vecmulmat (&v, &viewp, m); vecmulmat (&d, &dir, m); if (intersect_rect (scale.x, scale.z, scale.y / 2.0, v, d, &face_intersect[i]) == TRUE) { face_intersect[i].face = 2; transpose_mat (m); vecmulmat(&tmp, &face_intersect[i].s, m); face_intersect[i].s = tmp; gimp_vector3_set (&face_intersect[i++].n, 0.0, -1.0, 0.0); result = TRUE; } } /* Check if we've found the two possible intersection points */ /* ========================================================= */ if (i < 2) { /* Bottom: Rotate viewpoint and direction into rectangle's local coordinate system */ /* =============================================================================== */ rotatemat (90, &axis[0], m); vecmulmat (&v, &viewp, m); vecmulmat (&d, &dir, m); if (intersect_rect (scale.x, scale.z, -scale.y / 2.0, v, d, &face_intersect[i]) == TRUE) { face_intersect[i].face = 3; transpose_mat (m); vecmulmat (&tmp, &face_intersect[i].s, m); face_intersect[i].s = tmp; face_intersect[i].v = 1.0 - face_intersect[i].v; gimp_vector3_set (&face_intersect[i++].n, 0.0, 1.0, 0.0); result = TRUE; } } /* Check if we've found the two possible intersection points */ /* ========================================================= */ if (i < 2) { /* Left side: Rotate viewpoint and direction into rectangle's local coordinate system */ /* ================================================================================== */ rotatemat (90, &axis[1], m); vecmulmat (&v, &viewp, m); vecmulmat (&d, &dir, m); if (intersect_rect (scale.z, scale.y, scale.x / 2.0, v, d, &face_intersect[i]) == TRUE) { face_intersect[i].face = 4; transpose_mat (m); vecmulmat (&tmp, &face_intersect[i].s, m); face_intersect[i].s = tmp; gimp_vector3_set (&face_intersect[i++].n, 1.0, 0.0, 0.0); result = TRUE; } } /* Check if we've found the two possible intersection points */ /* ========================================================= */ if (i < 2) { /* Right side: Rotate viewpoint and direction into rectangle's local coordinate system */ /* =================================================================================== */ rotatemat (90, &axis[1], m); vecmulmat (&v, &viewp, m); vecmulmat (&d, &dir, m); if (intersect_rect (scale.z, scale.y, -scale.x / 2.0, v, d, &face_intersect[i]) == TRUE) { face_intersect[i].face = 5; transpose_mat (m); vecmulmat (&tmp, &face_intersect[i].s, m); face_intersect[i].u = 1.0 - face_intersect[i].u; gimp_vector3_set (&face_intersect[i++].n, -1.0, 0.0, 0.0); result = TRUE; } } /* Sort intersection points */ /* ======================== */ if (face_intersect[0].t > face_intersect[1].t) { face_tmp = face_intersect[0]; face_intersect[0] = face_intersect[1]; face_intersect[1] = face_tmp; } return result; }