示例#1
0
ConditionVariable::ConditionVariable() {
    int err;
    if ((err = pthread_cond_init(&cond, NULL)) != 0)
        Severe("Error from pthread_cond_init: %s", strerror(err));
    if ((err = pthread_mutex_init(&mutex, NULL)) != 0)
        Severe("Error from pthread_mutex_init: %s", strerror(err));
}
示例#2
0
void RWMutexLock::UpgradeToWrite() {
    Assert(type == READ);
    int err;
    if ((err = pthread_rwlock_unlock(&mutex.mutex)) != 0)
        Severe("Error from pthread_rwlock_unlock: %s", strerror(err));
    if ((err = pthread_rwlock_wrlock(&mutex.mutex)) != 0)
        Severe("Error from pthread_rwlock_wrlock: %s", strerror(err));
    type = WRITE;
}
示例#3
0
void RWMutexLock::DowngradeToRead() {
    Assert(type == WRITE);
    int err;
    if ((err = pthread_rwlock_unlock(&mutex.mutex)) != 0)
        Severe("Error from pthread_rwlock_unlock: %s", strerror(err));
    if ((err = pthread_rwlock_rdlock(&mutex.mutex)) != 0)
        Severe("Error from pthread_rwlock_rdlock: %s", strerror(err));
    type = READ;
}
示例#4
0
Semaphore::~Semaphore() {
#ifdef __OpenBSD__
    int err = sem_destroy(sem);
    free((void *)sem);
    sem = NULL;
    if (err != 0)
        Severe("Error from sem_destroy: %s", strerror(err));
#else
    int err;
    if ((err = sem_close(sem)) != 0)
        Severe("Error from sem_close: %s", strerror(err));
#endif // !__OpenBSD__
}
示例#5
0
void Scene::Intersect(const RayDifferential* ray, Intersection *isect, bool* hit,
  const int & count, const unsigned int & samplesPerPixel
  #ifdef STAT_RAY_TRIANGLE
  , Spectrum *Ls
  #endif
  ) const {
    RayHieararchy* rh = dynamic_cast<RayHieararchy*>(aggregate);
    if ( rh != NULL){
      rh->Intersect(ray, isect, hit, count
      #ifdef STAT_RAY_TRIANGLE
        ,Ls
      #endif
      );
      return;
    }
    RayBVH* rbvh = dynamic_cast<RayBVH*>(aggregate);
    if ( rbvh != NULL){
      rbvh->Intersect(ray, isect, hit, count
      #ifdef STAT_RAY_TRIANGLE
        ,Ls
      #endif
      );
      return;
    }
    NaiveAccel* na = dynamic_cast<NaiveAccel*>(aggregate);
    if ( na != NULL)
      na->Intersect(ray, isect, hit, count);
    else
      Severe("Called Intersect with unsupported aggregate!");
  }
示例#6
0
RWMutex::RWMutex() {
    numWritersWaiting = numReadersWaiting = activeWriterReaders = 0;
    InitializeCriticalSection(&cs);

    hReadyToRead = CreateEvent(NULL, TRUE, FALSE, NULL);
    if (hReadyToRead == NULL) {
        Severe("Error creating event for RWMutex: %d", GetLastError());
    }

    hReadyToWrite = CreateSemaphore(NULL, 0, 1, NULL);
    if (hReadyToWrite == NULL) {
        DWORD lastError = GetLastError();
        CloseHandle(hReadyToRead);
        Severe("Error creating semaphore for RWMutex: %d", lastError);
    }
}
示例#7
0
Semaphore::Semaphore() {
#ifdef __OpenBSD__
    sem = (sem_t *)malloc(sizeof(sem_t));
    if (!sem)
        Severe("Error from sem_open");
    int err = sem_init(sem, 0, 0);
    if (err == -1)
        Severe("Error from sem_init: %s", strerror(err));
#else
    char name[32];
    sprintf(name, "pbrt.%d-%d", (int)getpid(), count++);
    sem = sem_open(name, O_CREAT, S_IRUSR|S_IWUSR, 0);
    if (!sem)
        Severe("Error from sem_open");
#endif // !__OpenBSD__
}
示例#8
0
void TasksCleanup() {
#ifdef PBRT_USE_GRAND_CENTRAL_DISPATCH
    return;
#else // // PBRT_USE_GRAND_CENTRAL_DISPATCH
    {   MutexLock lock(*taskQueueMutex);
        Assert(taskQueue.size() == 0);
    }

    static const int nThreads = NumSystemCores();
    workerSemaphore.Post(nThreads);

    if (threads != NULL) {
#ifdef PBRT_HAS_PTHREADS
        for (int i = 0; i < nThreads; ++i) {
            int err = pthread_join(threads[i], NULL);
            if (err != 0)
                Severe("Error from pthread_join: %s", strerror(err));
        }
#endif
#ifdef WIN32
        WaitForMultipleObjects(nThreads, threads, TRUE, INFINITE);
        for (int i = 0; i < nThreads; ++i) {
            CloseHandle(threads[i]);
        }
#endif // WIN32
        delete[] threads;
        threads = NULL;
    }
#endif // PBRT_USE_GRAND_CENTRAL_DISPATCH
}
示例#9
0
void Aggregate::ComputeScatteringFunctions(SurfaceInteraction *isect,
                                           MemoryArena &arena,
                                           TransportMode mode,
                                           bool allowMultipleLobes) const {
    Severe(
        "Aggregate::ComputeScatteringFunctions() method"
        "called; should have gone to GeometricPrimitive");
}
示例#10
0
文件: timer.cpp 项目: acpa2691/cs348b
// Timer Method Definitions
Timer::Timer()
{
#if defined( IRIX ) || defined( IRIX64 )
	// IRIX Timer Initialization
	__psunsigned_t phys_addr, raddr;
	int poffmask = getpagesize() - 1;
	int counterSize = syssgi(SGI_CYCLECNTR_SIZE);
	
	phys_addr = syssgi(SGI_QUERY_CYCLECNTR, &(cycleval));
	if (phys_addr == ENODEV) {
		Severe( "Sorry, this SGI doesn't support timers." );
	}
	
	raddr = phys_addr & ~poffmask;
	fd = open("/dev/mmem", O_RDONLY);
	
	if (counterSize == 64) {
		iotimer_addr64 =
			(volatile iotimer64_t *)mmap(0, poffmask, PROT_READ,
			MAP_PRIVATE, fd, (off_t)raddr);
		unmapLocation = (void *)iotimer_addr64;
		unmapSize = poffmask;
		iotimer_addr64 = (iotimer64_t *)((__psunsigned_t)iotimer_addr64 +
				(phys_addr & poffmask));
	}
	else if (counterSize == 32) {
		iotimer_addr32 = (volatile iotimer32_t *)mmap(0, poffmask, PROT_READ,
				MAP_PRIVATE, fd,
				(off_t)raddr);
		unmapLocation = (void *)iotimer_addr32;
		unmapSize = poffmask;
		iotimer_addr32 = (iotimer32_t *)((__psunsigned_t)iotimer_addr32 +
				(phys_addr & poffmask));
	}
	else {
		Severe( "Fatal timer init error" );
	}
#elif defined( WIN32 )
	// Windows Timer Initialization
	QueryPerformanceFrequency( &performance_frequency );
	one_over_frequency = 1.0/((double)performance_frequency.QuadPart);
#endif
	time0 = elapsed = 0;
	running = 0;
}
	AsymptoticNewmark::AsymptoticNewmark(Scalar beta, Scalar gamma, int DOFS, Scalar massDamp, Scalar stiffDamp, Scalar ts,
		const Reference<Mesh>& m, const Reference<NodeIndexer>& nodeIndexer, ReducedHyperelasticMaterial* mater)
		:Intergrator(DOFS, massDamp, stiffDamp, ts){
		int orderCount = mater->getNonlinearAsymptoticOrder();
		int entrys = orderCount*dofs;
		d = allocAligned<Scalar>(entrys);
		v = allocAligned<Scalar>(entrys);
		a = allocAligned<Scalar>(entrys);
		pre_d = allocAligned<Scalar>(entrys);
		pre_v = allocAligned<Scalar>(entrys);
		pre_a = allocAligned<Scalar>(entrys);
		externalVirtualWork = allocAligned<Scalar>(entrys);

		memset(d, 0, entrys*sizeof(Scalar));
		memset(v, 0, entrys*sizeof(Scalar));
		memset(a, 0, entrys*sizeof(Scalar));
		memset(pre_d, 0, entrys*sizeof(Scalar));
		memset(pre_v, 0, entrys*sizeof(Scalar));
		memset(pre_a, 0, entrys*sizeof(Scalar));
		memset(externalVirtualWork, 0, entrys*sizeof(Scalar));

		mesh = m;
		indexer = nodeIndexer;
		material = mater;
		betaDeltaT2 = beta*timeStep*timeStep;
		gammaDeltaT = gamma*timeStep;
		minusBetaDeltaT2 = timeStep*timeStep*Scalar(0.5) - betaDeltaT2;
		minusGammaDeltaT = timeStep - gammaDeltaT;
		totalDofs = indexer->getMatrixOrder(mesh);
		frequencies2 = allocAligned<Scalar>(dofs);
		basises = allocAligned<Scalar>(dofs*totalDofs);

		SparseMatrixAssembler M(totalDofs);
		SparseMatrixAssembler K(totalDofs);
		material->generateMassMatrix(mesh, indexer, M);
		material->generateStiffnessMatrix(mesh, indexer, K); 

		EigenSolver slover;
		slover.getEigenValVectors(dofs, M, K, frequencies2, basises);

		material->preprocessWithReduction(mesh, indexer);
		loadFactors = allocAligned<Scalar>(orderCount);
		fullDisplacements = allocAligned<Scalar>(orderCount*totalDofs);
		vwBuffer = allocAligned<Scalar>(totalDofs);

#ifdef ODER_DEBUG
		for (int i = 0; i < dofs; i++){
			if (frequencies2[i] < 0.0)
				Severe("Stiffness Matrix is not semi-define");
		}
#endif
	}
示例#12
0
void TasksInit() {
#ifdef PBRT_USE_GRAND_CENTRAL_DISPATCH
    return;
#else // PBRT_USE_GRAND_CENTRAL_DISPATCH
    static const int nThreads = NumSystemCores();
#ifdef PBRT_HAS_PTHREADS
    threads = new pthread_t[nThreads];
    for (int i = 0; i < nThreads; ++i) {
        int err = pthread_create(&threads[i], NULL, &taskEntry, reinterpret_cast<void *>(i));
        if (err != 0)
            Severe("Error from pthread_create: %s", strerror(err));
    }
#endif // !PBRT_HAS_PTHREADS
#ifdef WIN32
    threads = new HANDLE[nThreads];
    for (int i = 0; i < nThreads; ++i) {
        threads[i] = CreateThread(NULL, 0, taskEntry, reinterpret_cast<void *>(i), 0, NULL);
        if (threads[i] == NULL)
            Severe("Error from CreateThread");
    }
#endif // WIN32
#endif // PBRT_USE_GRAND_CENTRAL_DISPATCH
}
示例#13
0
float InterpolateSpectrumSamples(const float *lambda, const float *vals,
                                 int n, float l) {
    for (int i = 0; i < n-1; ++i) Assert(lambda[i+1] > lambda[i]);
    if (l <= lambda[0])   return vals[0];
    if (l >= lambda[n-1]) return vals[n-1];
    for (int i = 0; i < n-1; ++i) {
        if (l >= lambda[i] && l <= lambda[i+1]) {
            float t = (l - lambda[i]) / (lambda[i+1] - lambda[i]);
            return Lerp(t, vals[i], vals[i+1]);
        }
    }
    Severe("Fatal logic error in InterpolateSpectrumSamples()");
    return 0.f;
}
示例#14
0
unsigned int Scene::MaxRaysPerCall() const {
  RayHieararchy* rh = dynamic_cast<RayHieararchy*>(aggregate);
  if ( rh != NULL)
    return rh->MaxRaysPerCall();
  RayBVH* rbvh = dynamic_cast<RayBVH*>(aggregate);
  if ( rbvh != NULL)
    return rbvh->MaxRaysPerCall();
  NaiveAccel* na = dynamic_cast<NaiveAccel*>(aggregate);
  if ( na != NULL)
    return na->MaxRaysPerCall();
  else
    Severe("Called MaxRaysPerCall with unsoppurted aggregate!");
  return 1;
}
示例#15
0
 bool XmlParseConfig(Config &c, TiXmlElement *conf)
 {
     if ( conf == NULL ) return false;
     stringstream ss;
     TiXmlElement *config = conf->FirstChildElement();
     for ( ; config; config = config->NextSiblingElement() ) {
         if ( config->Type() != TiXmlNode::TINYXML_ELEMENT ) continue;
         string configType(config->Value());
         const char *name = config->Attribute("Name");
         if ( !name ) {
             Severe("Config Name attribute missing");
             return false;
         }
         string configName(name);
         if ( configType == "Float" ) {
             double value;
             if ( !config->Attribute("Value", &value) ) {
                 ss << "Config [" << configName << "] missing value";
                 Severe(ss);
                 return false;
             }
             c.AddAttribute(configName, (float) value);
         } else if ( configType == "Int32" ) {
             int i;
             if ( !config->Attribute("Value", &i) ) {
                 ss << "Config [" << configName << "] missing value";
                 Severe(ss);
                 return false;
             }
             c.AddAttribute(configName, i);
         } else if ( configType == "Vector" ) {
             Vector vec;
             TiXmlElement *elemVec = config->FirstChildElement("Value");
             if ( !elemVec ) {
                 ss << "Config [" << configName << "] missing value";
                 Severe(ss);
                 return false;
             }
             if ( !XmlParseVector(vec, elemVec) ) return false;
             c.AddAttribute(configName, vec);
         } else if ( configType == "Bool" ) {
             int b;
             if ( !config->Attribute("Value", &b) ) {
                 ss << "Config [" << configName << "] missing value";
                 Severe(ss);
                 return false;
             }
             c.AddAttribute(configName, b != 0);
         } else {
             ss << "Unknown config type: [" << configType << "]";
             Severe(ss);
             return false;
         }
     }
     return true;
 }
示例#16
0
void RealisticCamera::ComputeThickLensApproximation(Float pz[2],
        Float fz[2]) const {
    // Find height $x$ from optical axis for parallel rays
    Float x = .001 * film->diagonal;

    // Compute cardinal points for film side of lens system
    Ray rScene(Point3f(x, 0, LensFrontZ() + 1), Vector3f(0, 0, -1));
    Ray rFilm;
    bool ok = TraceLensesFromScene(rScene, &rFilm);
    if (!ok)
        Severe(
            "Unable to trace ray from scene to film for thick lens "
            "approximation. Is aperture stop extremely small?");
    ComputeCardinalPoints(rScene, rFilm, &pz[0], &fz[0]);

    // Compute cardinal points for scene side of lens system
    rFilm = Ray(Point3f(x, 0, LensRearZ() - 1), Vector3f(0, 0, 1));
    ok = TraceLensesFromFilm(rFilm, &rScene);
    if (!ok)
        Severe(
            "Unable to trace ray from film to scene for thick lens "
            "approximation. Is aperture stop extremely small?");
    ComputeCardinalPoints(rFilm, rScene, &pz[1], &fz[1]);
}
示例#17
0
 bool XmlParseColor(Color &c, TiXmlElement *color)
 {
     if ( color == NULL ) return false;
     double r, g, b;
     const char *pAttrR = color->Attribute("R", &r);
     const char *pAttrG = color->Attribute("G", &g);
     const char *pAttrB = color->Attribute("B", &b);
     if ( !pAttrR || !pAttrG || !pAttrB ) {
         Severe("Invalid color value");
         return false;
     }
     c.x = (float) r;
     c.y = (float) g;
     c.z = (float) b;
     return true;
 }
示例#18
0
static Float convert(void *p, int offset, int type) {
    switch (type) {
    case TINYEXR_PIXELTYPE_UINT: {
        int32_t *pix = (int32_t *)p;
        return pix[offset];
    }
    case TINYEXR_PIXELTYPE_HALF:
    case TINYEXR_PIXELTYPE_FLOAT: {
        float *pix = (float *)p;
        return pix[offset];
    }
    default:
        Severe("Unexpected pixel type in EXR image");
        return 0;
    }
}
示例#19
0
 bool XmlParseVector(Vector &v, TiXmlElement *vec)
 {
     if ( vec == NULL ) return false;
     double x, y, z;
     const char *pAttrX = vec->Attribute("X", &x);
     const char *pAttrY = vec->Attribute("Y", &y);
     const char *pAttrZ = vec->Attribute("Z", &z);
     if ( !pAttrX || !pAttrY || !pAttrZ ) {
         Severe("Invalid vector value");
         return false;
     }
     v.x = (float) x;
     v.y = (float) y;
     v.z = (float) z;
     return true;
 }
示例#20
0
RealisticCamera *CreateRealisticCamera(const ParamSet &params,
        const AnimatedTransform &cam2world, Film *film) {
	// Extract common camera parameters from \use{ParamSet}
	float hither = params.FindOneFloat("hither", -1);				
	float yon = params.FindOneFloat("yon", -1);						
	float shutteropen = params.FindOneFloat("shutteropen", -1);		
	float shutterclose = params.FindOneFloat("shutterclose", -1);	

	// Realistic camera-specific parameters
	string specfile = params.FindOneString("specfile", "");			
	float filmdistance = params.FindOneFloat("filmdistance", 70.0); 
 	float fstop = params.FindOneFloat("aperture_diameter", 1.0);
	float filmdiag = params.FindOneFloat("filmdiag", 35.0);			

	Assert(hither != -1 && yon != -1 && shutteropen != -1 &&
		shutterclose != -1 && filmdistance!= -1);
	if (specfile == "") {
	    Severe( "No lens spec file supplied!\n" );
	}
	return new RealisticCamera(cam2world, hither, yon,
				   shutteropen, shutterclose, filmdistance, fstop, 
				   specfile, filmdiag, film);
}
示例#21
0
文件: debug.cpp 项目: acpa2691/cs348b
Spectrum DebugIntegrator::Li(const Scene *scene,
		const RayDifferential &ray, const Sample *sample,
		float *alpha) const {
	Intersection isect;
	Spectrum L(0.);
	bool hitSomething;
	BSDF *bsdf = NULL;

	if (alpha) *alpha = 1;

	hitSomething = scene->Intersect(ray, &isect);
	if (hitSomething) {
		bsdf = isect.GetBSDF(ray);
	}

	float color[3] = {0,0,0};

	int i;
	for (i = 0 ; i < 3 ; i++)
	{
		if (debug_variable[i] == DEBUG_HIT_SOMETHING)
		{
			color[i] = hitSomething ? 1 : 0;
		}
		else if (debug_variable[i] == DEBUG_ONE)
		{
			color[i] = 1;
		}
		else if (debug_variable[i] == DEBUG_ZERO)
		{
			color[i] = 0;
		}
		else if (hitSomething)
		{
			switch( debug_variable[i] )
			{
				case DEBUG_U:
					color[i] = isect.dg.u;
					break;
				case DEBUG_V:
					color[i] = isect.dg.v;
					break;
				case DEBUG_GEOM_NORMAL_X:
					color[i] = fabsf(isect.dg.nn.x);
					break;
				case DEBUG_GEOM_NORMAL_Y:
					color[i] = fabsf(isect.dg.nn.y);
					break;
				case DEBUG_GEOM_NORMAL_Z:
					color[i] = fabsf(isect.dg.nn.z);
					break;
				case DEBUG_SHAD_NORMAL_X:
					color[i] = fabsf(bsdf->dgShading.nn.x);
					break;
				case DEBUG_SHAD_NORMAL_Y:
					color[i] = fabsf(bsdf->dgShading.nn.y);
					break;
				case DEBUG_SHAD_NORMAL_Z:
					color[i] = fabsf(bsdf->dgShading.nn.z);
					break;
				default:
					break;
			}
		}
		if (color[i] < 0)
		{
			Severe( "i = %d\ndebug_variable[i] = %d\nhit_something = %d\ncolor[i] = %f", i, debug_variable[i], hitSomething, color[i] );
		}
	}

	L = Spectrum(color);
	return L;
}
示例#22
0
文件: curve.cpp 项目: fseraph/pbrt-v3
Interaction Curve::Sample(const Point2f &u) const {
    Severe("Curve::Sample not implemented.");
    return Interaction();
}
示例#23
0
bool Hyperboloid::Sample(const Point2f &sample, Interaction *it) const {
    Severe("Hyperboloid::Sample not implemented.");
    return false;
}
示例#24
0
文件: mlt.cpp 项目: NickYang/pbrt-v3
std::unique_ptr<Sampler> MLTSampler::Clone(int seed) {
    Severe("MLTSampler::Clone() is not implemented");
    return nullptr;
}
示例#25
0
BSSRDF *Aggregate::GetBSSRDF(const DifferentialGeometry &,
                             const Transform &, MemoryArena &) const {
    Severe("Aggregate::GetBSSRDF() method"
           "called; should have gone to GeometricPrimitive");
    return NULL;
}
示例#26
0
const AreaLight *Aggregate::GetAreaLight() const {
    Severe("Aggregate::GetAreaLight() method"
           "called; should have gone to GeometricPrimitive");
    return NULL;
}
示例#27
0
void Primitive::Refine(vector<Reference<Primitive> > &refined) const {
    Severe("Unimplemented Primitive::Refine() method called!");
}
示例#28
0
float Shape::Area() const {
    Severe("Unimplemented Shape::Area() method called");
    return 0.;
}
示例#29
0
bool Shape::IntersectP(const Ray &ray) const {
    Severe("Unimplemented Shape::IntersectP() method called");
    return false;
}
示例#30
0
bool Shape::Intersect(const Ray &ray, float *tHit, float *rayEpsilon,
                      DifferentialGeometry *dg) const {
    Severe("Unimplemented Shape::Intersect() method called");
    return false;
}