Point SphereShape::sample_point(float u1, float u2, Normal& out_n, float& out_ray_epsilon) const { Vec3 w = uniform_sphere_sample(u1, u2); out_n = Normal(w); out_ray_epsilon = 5e-3f * this->radius; return Point() + Vector(w * this->radius); }
// ---------------------------------------------------------------- copy constructor SolidCylinder::SolidCylinder(const SolidCylinder& cyl) : Compound(cyl), bottom(cyl.bottom), top(cyl.top), radius(cyl.radius), box(Point3D(-1.0*radius,bottom , -1.0*radius), Point3D(1.0*radius,top , 1.0*radius)) {objects.push_back(new Disk(Point3D(0, bottom, 0), Normal(0, -1, 0), radius)); objects.push_back(new Disk(Point3D(0, top, 0), Normal(0, 1, 0), radius)); objects.push_back(new OpenCylinder(bottom,top,radius));}
Vector2D Vector2D::Reflect(const Vector2D & v, const Vector2D &a) { Vector2D n = Normal(a); float co = -2 * ((float)v.Dot(n) / (n.Magnitude() * n.Magnitude())); Vector2D r = {}; r.x = v.x + co * n.x; r.y = r.y + co * n.y; return r; }
D3DXVECTOR3 rotate(D3DXVECTOR3 v, Quaternion q) { Quaternion q_, qv; q = Normal(q); q_.w = q.w; q_.x = -q.x; q_.y = -q.y; q_.z = -q.z; qv.w = 0; qv.x=v.x; qv.y=v.y; qv.z=v.z; Quaternion aa= q_*qv*q; return D3DXVECTOR3(aa.x, aa.y, aa.z); }
Point Cylinder::Sample(float u1, float u2, Normal *Ns) const { float z = Lerp(u1, zmin, zmax); float t = u2 * phiMax; Point p = Point(radius * cosf(t), radius * sinf(t), z); *Ns = Normalize((*ObjectToWorld)(Normal(p.x, p.y, 0.))); if (ReverseOrientation) *Ns *= -1.f; return (*ObjectToWorld)(p); }
bool DistanceEstimator::Intersect(const Ray &r, float *tHit, float *rayEpsilon, DifferentialGeometry *dg) const { bool succeed = DoesIntersect(r, tHit); if (!succeed) return false; Ray ray; (*WorldToObject)(r, &ray); Point p = ray(*tHit); *rayEpsilon = DE_params.hitEpsilon * DE_params.rayEpsilonMultiplier; Vector n = CalculateNormal(p, DE_params.normalEpsilon); Vector DPDU, DPDV; CoordinateSystem(n, &DPDU, &DPDV); const Transform &o2w = *ObjectToWorld; *dg = DifferentialGeometry(o2w(p), o2w(DPDU), o2w(DPDV), Normal(), Normal(), 0, 0, this); return true; }
Point3 SContext::DP(void) { SCDebugPrint("SContext::DP\n"); float d = (1.0f+DFACT)*0.1f/(DFACT+(float)fabs(DotProd(Normal(),viewDir))); dp = Point3(d,d,d); return dp; }
void PtrFreeScene :: translate_geometry() { //mesh_first_triangle_offset.resize(0); delete_array(mesh_first_triangle_offset); const uint n_vertices = data_set->GetTotalVertexCount(); const uint n_triangles = data_set->GetTotalTriangleCount(); // translate mesh normals, colors and uvs this->vertex_count = n_vertices; this->normals_count = n_vertices; this->colors_count = n_vertices; this->uvs_count = n_vertices; this->triangles_count = n_triangles; reset_array(this->vertexes, this->vertex_count); reset_array(this->normals, this->normals_count); reset_array(this->colors, this->colors_count); reset_array(this->uvs, this->uvs_count); reset_array(this->triangles, this->triangles_count); //normals.resize(n_vertices); //colors.resize(n_vertices); //uvs.resize(n_vertices); uint index = 0; // aux data to later translate triangles uint *mesh_offsets = new uint[original_scene->objects.size()]; uint v_index = 0; for (uint i = 0; i < original_scene->objects.size(); ++i) { const luxrays::ExtMesh* mesh = original_scene->objects[i]; mesh_offsets[i] = v_index; for(uint j = 0; j < mesh->GetTotalVertexCount(); ++j) { normals[index] = Normal(mesh->GetNormal(j)); colors[index] = Spectrum(mesh->GetColor(j)); uvs[index] = (mesh->HasUVs()) ? mesh->GetUV(j) : UV(0.f, 0.f); vertexes[index] = Point(mesh->GetVertex(j)); index++; } v_index += mesh->GetTotalVertexCount(); } // translate mesh triangles //triangles.resize(n_triangles); index = 0; for(uint i = 0; i < original_scene->objects.size(); ++i) { const luxrays::ExtMesh* mesh = original_scene->objects[i]; const luxrays::Triangle *mtris = mesh->GetTriangles(); const uint moffset = mesh_offsets[i]; for (uint j = 0; j < mesh->GetTotalTriangleCount(); ++j) { triangles[index++] = Triangle( mtris[j].v[0] + moffset, mtris[j].v[1] + moffset, mtris[j].v[2] + moffset); } } delete[] mesh_offsets; }
boolean FileGetZeroedChunk (vbntype VbnBlk, blkhdrtype *BlkHdr, boolean Release, ft F,lt Z,zz *Status, numtype *Chunk) { bytessize UnitSize = 0; indextype UnitCount = 0; bytessize ChunkSize = 0; vbntype ChunkRefVbn = VbnBlk; chunkstruc ChunkRef; chunkstruc *ChunkRefPtr = &ChunkRef; addrtype ChunkAddr = NullPtr; /* Load Chunk Struc Into Core */ if (FileInBlk ((addrtype *)&ChunkRefPtr, sizeof(chunkstruc), BlkHdr, Release, McStat, &ChunkRefVbn)) { UnitSize = ChunkRefPtr->UnitSize; UnitCount = ChunkRefPtr->UnitCount; ChunkSize = UnitCount * UnitSize; if (!*Chunk) MemMakeChunk (UnitSize, UnitCount, ChunkRef.ExtendQty, DbmDbId, McStat, Chunk); if (Normal(*Status)) MemPutStackPtr (*Chunk, ChunkRef.StackPtr, McStat); if (!ChunkSize) if (sprintf (Msg, TraceStr(43), /* " ZERO BLOCK [%3u] ZERO Chunk[%4u](%2u * %2u)\n" */ VbnBlk, *Chunk, UnitCount, UnitSize)) TraceMsg (0, Msg); if (MemGetChunkAddr (*Chunk, McStat, &ChunkAddr)) memset (ChunkAddr, NULL, (size_t )ChunkSize); } if (Normal(*Status)) if (DeBug) MemDumpChunk (0, *Chunk, McStat); TRACK(TrackBak,"FileGetZeroedChunk\n"); return(STAT); }
void CBasePoly::SaveBasePolyLTA( CLTAFile* pFile, uint32 level ) { uint32 i; //write out the list of face indices PrependTabs(pFile, level); pFile->WriteStr("( f "); for( i=0; i < m_Indices; i++ ){ pFile->WriteStrF("%i ", m_Indices[i] ); } pFile->WriteStr(")"); //write out the surface normal PrependTabs(pFile, level); pFile->WriteStrF("( n %f %f %f )", Normal().x, Normal().y, Normal().z ); PrependTabs(pFile, level); pFile->WriteStrF("( dist %f )", Dist() ); }
double Student(long n) /* =========================================== * Returns a student-t distributed real number. * NOTE: use n > 0 * =========================================== */ { return (Normal(0.0, 1.0) / sqrt(Chisquare(n) / n)); }
double Lognormal(double a, double b) /* ==================================================== * Returns a lognormal distributed positive real number. * NOTE: use b > 0.0 * ==================================================== */ { return (exp(a + b * Normal(0.0, 1.0))); }
void sampleEmissionArea(EmissionRecord &eRec, const Point2 &sample) const { if (eRec.type == EmissionRecord::ENormal) { Vector d = squareToSphere(sample); eRec.sRec.p = m_bsphere.center + d * m_bsphere.radius; eRec.sRec.n = Normal(-d); eRec.pdfArea = 1.0f / (4 * M_PI * m_bsphere.radius * m_bsphere.radius); eRec.value = Spectrum(M_PI); } else { /* Preview mode, which is more suitable for VPL-based rendering: approximate the infinitely far-away source with set of diffuse point sources */ const Float radius = m_bsphere.radius * 1.5f; Vector d = squareToSphere(sample); eRec.sRec.p = m_bsphere.center + d * radius; eRec.sRec.n = Normal(-d); eRec.pdfArea = 1.0f / (4 * M_PI * radius * radius); eRec.value = Le(d) * M_PI; } }
void samplePosition(PositionSamplingRecord &pRec, const Point2 &sample) const { const Transform &trafo = m_objectToWorld->eval(pRec.time); Point2 p = warp::squareToUniformDiskConcentric(sample); pRec.p = trafo(Point3(p.x, p.y, 0)); pRec.n = normalize(trafo(Normal(0, 0, 1))); pRec.pdf = m_invSurfaceArea; pRec.measure = EArea; }
Spectrum samplePosition(PositionSamplingRecord &pRec, const Point2 &sample, const Point2 *extra) const { const Transform &trafo = m_worldTransform->eval(pRec.time); pRec.p = trafo(Point(0.0f)); pRec.n = Normal(0.0f); pRec.pdf = 1.0f; pRec.measure = EDiscrete; return Spectrum(1.0f); }
// ---------------------------------------------------------------------- default constructor SolidCylinder::SolidCylinder(void) : Compound(), bottom(1), top(1), radius(1), box(Point3D(-1.0*radius,bottom , -1.0*radius), Point3D(1.0*radius,top , 1.0*radius)) { objects.push_back(new Disk(Point3D(0, bottom, 0), Normal(0, -1, 0), radius)); objects.push_back(new Disk(Point3D(0, top, 0), Normal(0, 1, 0), radius)); objects.push_back(new OpenCylinder(bottom,top,radius)); }
// ---------------------------------------------------------------------- constructor SolidCylinder::SolidCylinder(const float bot, const float t, const float r) : Compound(), bottom(bot), top(t), radius(r), box(Point3D(-1.0*r,bot , -1.0*r), Point3D(1.0*r,t , 1.0*r)) { objects.push_back(new Disk(Point3D(0, bottom, 0), Normal(0, -1, 0), radius)); objects.push_back(new Disk(Point3D(0, top, 0), Normal(0, 1, 0), radius)); objects.push_back(new OpenCylinder(bottom,top,radius)); }
void IntersectionPoint(const Circle& c1, const Circle& c2, Point& p1, Point& p2) { double d = Length(c1.c - c2.c); double l = (c1.r*c1.r + d*d - c2.r*c2.r) / (2 * d); double h = sqrt(c1.r*c1.r - l*l); Point mid = c1.c + unit(c2.c-c1.c) * l; Vector t = Normal(c2.c - c1.c) * h; p1 = mid + t; p2 = mid - t; }
Point Disk::Sample(float u1, float u2, Normal *Ns) const { Point p; ConcentricSampleDisk(u1, u2, &p.x, &p.y); p.x *= radius; p.y *= radius; p.z = height; *Ns = Normalize((*ObjectToWorld)(Normal(0,0,1))); if (ReverseOrientation) *Ns *= -1.f; return (*ObjectToWorld)(p); }
int mlStrcmpEnd(char* string1, char* string2) { int i = 0, len1 = 0, len2 = 0; while (string1[i] != '\r' && string1[i] != 'ý') { i++; } int j = 0; while (string2[j] != '\r' && string1[i] != 'ý') { j++; } len1 = i; len2 = j; i = 1; j = 1; if (string2[len2 - 1] >= 'A' && string2[len2 - 1] <= 'Z' && string1[len1 - 1] >= 'A' && string1[len1 - 1] <= 'Z') return 0; else while (len1 - i >= 0 && len2 - j >= 0) { if (!Normal(string1, i)) i++; if (!Normal(string2, j)) j++; if (Normal(string1, i) && Normal(string2, j)) { if (string1[len1 - i] == string2[len2 - j]) { i++; j++; } else if (string1[len1 - i] > string2[len2 - j]) return 1; else if (string1[len1 - i] < string2[len2 - j]) return -1; else return 0; } } return 0; }
Spectrum PointLight::sample_ray_radiance(const Scene&, Ray& out_ray, Normal& out_nn, float& out_pdf, LightRaySample sample) const { Vec3 wi = uniform_sphere_sample(sample.uv_dir.x, sample.uv_dir.y); out_ray = Ray(this->pt, Vector(wi), 0.f); out_nn = Normal(wi); out_pdf = uniform_sphere_pdf(); return this->intensity; }
bool plane_t::PlaneLineIntersection(vec3 start, vec3 end, vec3 *hitpoint) { float d1, d2; d1 = Distance(start); d2 = Distance(end); if (d1 == d2) { return false; } if (d1 > 0.0f && d2 > 0.0f) { return false; } if (d1 < 0.0f && d2 < 0.0f) { return false; } // calculate the intersection { float fraction; fraction = (d1 / (d1 - d2)); *hitpoint = start + fraction * (start - end); return true; } #if 0 // calculate a more precise intersection { // this will only work if the normal is normalized vec3 n = Normal(); fraction = (d1 / (d1 - d2)); for(i = 0; i < 3; i++) { if (n[i] == 1) { hitpoint[i] = d; } else if (n[i] == -1) { hitpoint[i] = -d; } else { hitpoint[i] = start[i] + fraction * (start[i] - end[i]); } } } #endif }
/* 14.1.5 */ boolean Is_List01Member (tokentype *ListTkn, tokentype *MemberTkn, ft F,lt Z,zz *Status, tokentype *NodeTkn) { listheadtype *HeadObj = NullPtr; tokentype NextNode = NullToken; listnodetype *NodeObj = NullPtr; NextNode.DbId = ListTkn->DbId; if (ListBug || DeBug) if (sprintf (Msg, "\n Is_List01Member[%4u:%6u]:: Token=[%2u:%4u] \n", ListTkn->DbId, ListTkn->Handle, MemberTkn->DbId, MemberTkn->Handle)) TraceMsg (0, Msg); if (OaGetObject (ListTkn, McStat, (addrtype *)&HeadObj)) for (NextNode.Handle = HeadObj->FirstNode; Normal(*Status) && NextNode.Handle;) { if (OaGetObject (&NextNode, McStat, (addrtype *)&NodeObj)) if (NodeObj->NodeObject.Handle == MemberTkn->Handle && NodeObj->NodeObject.DbId == MemberTkn->DbId) { if (ListBug || DeBug) if (sprintf (Msg, " ...NodeTkn =[%4u:%6u]\n", NodeTkn->DbId, NodeTkn->Handle)) TraceMsg (0, Msg); return (True); } else NextNode.Handle = NodeObj->NextNode; } if (ListBug || DeBug) TraceMsg (0, "\n ... Not a Member.\n"); if (Normal(*Status)) return (False); TRACK(TrackBak,"Is_List01Member\n"); return (STAT); }
/** This function initializes all global generators by @a seed value. @param seed The seed value of all generators. */ void srand(RandomValue seed) { OMNI_MT_CODE(sync::AutoLock guard(g_lock())); g_rand() = Random(seed); g_unif() = Uniform(seed); g_norm() = Normal(seed); g_exp() = Exponential(seed); g_seed() = seed; }
/* ================ idPlane::PlaneIntersection ================ */ bool idPlane::PlaneIntersection( const idPlane &plane, idVec3 &start, idVec3 &dir ) const { double n00, n01, n11, det, invDet, f0, f1; n00 = Normal().LengthSqr(); n01 = Normal() * plane.Normal(); n11 = plane.Normal().LengthSqr(); det = n00 * n11 - n01 * n01; if ( idMath::Fabs(det) < 1e-6f ) { return false; } invDet = 1.0f / det; f0 = ( n01 * plane.d - n11 * d ) * invDet; f1 = ( n01 * d - n00 * plane.d ) * invDet; dir = Normal().Cross( plane.Normal() ); start = f0 * Normal() + f1 * plane.Normal(); return true; }
Point CylinderShape::sample_point(float u1, float u2, Normal& out_n, float& out_ray_epsilon) const { float z = lerp(u1, this->z_min, this->z_max); float phi = TWO_PI * u2; float cos_phi = cos(phi); float sin_phi = sin(phi); out_n = Normal(cos_phi, sin_phi, 0.f); out_ray_epsilon = 5e-3f; return Point(cos_phi * this->radius, sin_phi * this->radius, z); }
/*+-----------------------------------------------------------------------+*/ boolean MemDumpChunk (int MsgLevel, numtype Chunk, ft F,lt Z,zz *Status) { if (!Normal(*Status)) DumpChunkChunk (0, Chunk); else DumpChunkChunk (MsgLevel, Chunk); TRACK(TrackBak,"MemDumpChunk\n"); return(STAT); }
Spectrum DirectionalLight::sample_ray_radiance(const Scene& scene, Ray& out_ray, Normal& out_nn, float& out_pdf, LightRaySample sample) const { Vec2 disk_p = uniform_disk_sample(sample.uv_pos.x, sample.uv_pos.y); Point orig = scene.centroid - Vector(scene.radius * this->direction) + disk_p.x * this->s + disk_p.y * this->t; out_ray = Ray(orig, this->direction, 0.f); out_nn = Normal(this->direction); out_pdf = uniform_disk_pdf() / (PI * square(scene.radius)); return this->radiance; }
static inline typename PT::product_type PointLeftOfLine(const PT &p, const PT &a, const PT &b) { // normal vector of the line const PT normal = Normal(a, b); // vector ap const PT ap = p - a; // almost distance point from line (normal has to be normalized for that) return DotProduct<PT, typename PT::product_type>(normal, ap); }
double StochasticLib1::NormalTrunc(double m, double s, double limit) { // Truncated normal distribution // The tails are cut off so that the output // is in the interval from (m-limit) to (m+limit) if (limit < s) FatalError("limit out of range in NormalTrunc function"); double x; do { x = Normal(0., s); } while (fabs(x) > limit); // reject if beyond limit return x + m; }