Example #1
0
/*
#include <ctime>
#include <iostream>

struct FunctionTimer
{
	FunctionTimer(const char *f) : funcName(f), start(clock()) {
		std::cerr << "Entered " << funcName << std::endl;
		std::cerr.flush();
	}
	~FunctionTimer() {
		std::cerr << funcName << " finished at "
		          << (double(clock() - start) * 1000. / CLOCKS_PER_SEC) << " ms"
		          << std::endl;
		std::cerr.flush();
	}

	const char *funcName;
	clock_t start;
};
*/
void Library::collectBookFileNames(std::set<std::string> &bookFileNames, std::vector<shared_ptr<ZLInputStream> > &inputStreamCache) const {
	AppLog("Library::collectBookFileNames()");
//	FunctionTimer timer(__PRETTY_FUNCTION__);
	std::set<std::string> dirs;
	AppLog("collectDirNames");
	collectDirNames(dirs);

	while (!dirs.empty()) {
		std::string dirname = *dirs.begin();
		dirs.erase(dirs.begin());
		AppLog("dirname %s",dirname.c_str());
		ZLFile dirfile(dirname);
		std::vector<std::string> files;
		bool inZip = false;
		AppLog("dirfile.directory");
		shared_ptr<ZLDir> dir = dirfile.directory();
		if (dir.isNull()) {
			AppLog("dir.isNull");
			continue;
		}
		
		if (!dirfile.isDirectory())
			inputStreamCache.push_back(dirfile.inputStream());

		if (dirfile.extension() == "zip") {
			ZLFile phys(dirfile.physicalFilePath());
			if (!BooksDBUtil::checkInfo(phys)) {
				BooksDBUtil::resetZipInfo(phys);
				BooksDBUtil::saveInfo(phys);
			}
			BooksDBUtil::listZipEntries(dirfile, files);
			inZip = true;
		} else {
			dir->collectFiles(files, true);
		}
		//std::cerr.precision(5);
		if (!files.empty()) {
			const bool collectBookWithoutMetaInfo = CollectAllBooksOption.value();
			for (std::vector<std::string>::const_iterator jt = files.begin(); jt != files.end(); ++jt) {
				const std::string fileName = (inZip) ? (*jt) : (dir->itemPath(*jt));
				AppLog("fileName %s",fileName.c_str());
				ZLFile file(fileName);
//				std::cerr << "Check file \"" << fileName << "\" ... ";
//				std::cerr.flush();
//				clock_t start = clock();
				if (PluginCollection::Instance().plugin(file, !collectBookWithoutMetaInfo) != 0) {
					bookFileNames.insert(fileName);
				// TODO: zip -> any archive
				} else if (file.extension() == "zip") {
					if (myScanSubdirs || !inZip) {
						AppLog("myScanSubdirs fileName %s",fileName.c_str());
						dirs.insert(fileName);
					}
				}
//				std::cerr << (double(clock() - start) * 1000. / CLOCKS_PER_SEC) << " ms" << std::endl;
//				std::cerr.flush();
			}
		}
	}
}
Example #2
0
        DNekMatSharedPtr StdNodalTriExp::GenNBasisTransMatrix()
        {
            int             i,j;
            Array<OneD, const NekDouble>  r, s; 
            Array<OneD, NekDouble> c(2);
            DNekMatSharedPtr Mat;

            Mat = MemoryManager<DNekMat>::AllocateSharedPtr(
                m_ncoeffs, m_ncoeffs);
            GetNodalPoints(r,s);

            //Store the values of m_phys in a temporary array
            int nqtot = GetTotPoints();
            Array<OneD,NekDouble> phys(nqtot);

            for(i = 0; i < m_ncoeffs; ++i)
            {
                // fill physical space with mode i
                StdTriExp::v_FillMode(i,phys);

                // interpolate mode i to the Nodal points 'j' and
                // store in outarray
                for(j = 0; j < m_ncoeffs; ++j)
                {
                    c[0] = r[j];
                    c[1] = s[j];
                    (*Mat)(j,i) = StdTriExp::v_PhysEvaluate(c,phys);
                }
            }
            return Mat;
        }
Example #3
0
void Ip2_FrictMat_FrictMat_ElectrostaticPhys::go(const shared_ptr<Material>& material1, const shared_ptr<Material>& material2, const shared_ptr<Interaction>& interaction)
{
	if (interaction->phys) return;

	// Inheritance & cast
	Ip2_FrictMat_FrictMat_LubricationPhys::go(material1,material2,interaction);
	LubricationPhys* ph = YADE_CAST<LubricationPhys*>(interaction->phys.get());
	shared_ptr<ElectrostaticPhys> phys(new ElectrostaticPhys(*ph));
	interaction->phys = phys;
	
	phys->DebyeLength = DebyeLength;
	phys->Z = Z;
}
Example #4
0
void *__pack_load(uint32_t key, size_t *size) {
	size_t i;

	if (!phys(__pack_vector)) {
		page_anon(__pack_vector, PAGESZ, PROT_READ | PROT_WRITE);
		__pack_vector[0].key = 0;
	}

	for (i = 0; __pack_vector[i].key; i++) {
		if (__pack_vector[i].key == key) {
			*size = __pack_vector[i].size;
			return __pack_vector[i].data;
		}
	}

	return NULL;
}
Example #5
0
void Library::collectBookFileNames(std::set<std::string> &bookFileNames) const {
	std::set<std::string> dirs;
	collectDirNames(dirs);

	while (!dirs.empty()) {
		std::string dirname = *dirs.begin();
		dirs.erase(dirs.begin());
		
		ZLFile dirfile(dirname);
		std::vector<std::string> files;
		bool inZip = false;

		shared_ptr<ZLDir> dir = dirfile.directory();
		if (dir.isNull()) {
			continue;
		}

		if (dirfile.extension() == "zip") {
			ZLFile phys(dirfile.physicalFilePath());
			if (!BooksDBUtil::checkInfo(phys)) {
				BooksDBUtil::resetZipInfo(phys);
				BooksDBUtil::saveInfo(phys);
			}
			BooksDBUtil::listZipEntries(dirfile, files);
			inZip = true;
		} else {
			dir->collectFiles(files, true);
		}
		if (!files.empty()) {
			const bool collectBookWithoutMetaInfo = CollectAllBooksOption.value();
			for (std::vector<std::string>::const_iterator jt = files.begin(); jt != files.end(); ++jt) {
				const std::string fileName = (inZip) ? (*jt) : (dir->itemPath(*jt));
				ZLFile file(fileName);
				if (PluginCollection::Instance().plugin(file, !collectBookWithoutMetaInfo) != 0) {
					bookFileNames.insert(fileName);
				// TODO: zip -> any archive
				} else if (file.extension() == "zip") {
					if (myScanSubdirs || !inZip) {
						dirs.insert(fileName);
					}
				}
			}
		}
	}
}
Example #6
0
int main( int argc, char const *argv[] )
{
   parseArgs(argc,argv);
   if( 1 < argc ){
      unsigned long address = strtoul( argv[1], 0, 0 );
      unsigned length ;
      if( 2 < argc )
         length = strtoul( argv[2], 0, 0 );
      else
         length = 512 ;

      physMem_t phys(address, length, deposit ? O_RDWR : O_RDONLY );
      if( phys.worked() )
      {
         if( deposit ){
            unsigned long *longs = (unsigned long *)phys.ptr();
            printf( "depositing 0x%08lx\n", value );
            while (0 < length) {
               *longs++ = value ;
               length -= sizeof(*longs);
            }
         }
	 if(!binary){
		 hexDumper_t dump( phys.ptr(), length, address );
		 while( dump.nextLine() )
		    printf( "%s\n", dump.getLine() );
	 }
	 else {
		 write(1, phys.ptr(), length);
		 fflush(stdout);
	 }
      }
      else
         perror( "map" );
   }
   else
      fprintf( stderr, "Usage: %s address [length=512]\n", argv[0] );
   return 0 ;
}
Example #7
0
void Directory::scan_dir(const ACE_TString& relative, DDS_Dirent& dir,
                         unsigned int overflow_index)
{
  ACE_TString path = physical_dirname_ + relative;
  add_slash(path);

  while (DDS_DIRENT* ent = dir.read()) {
    if (ent->d_name[0] == ACE_TEXT('.') && (!ent->d_name[1] ||
        (ent->d_name[1] == ACE_TEXT('.') && !ent->d_name[2]))) {
      continue; // skip '.' and '..'
    }

    ACE_TString file = path + ent->d_name;

    if (is_dir(file.c_str())) {
      ACE_TString phys(relative);
      add_slash(phys);
      phys += ent->d_name;

      if (ACE_OS::strncmp(ent->d_name, ACE_TEXT("_overflow."), 10) == 0) {
        unsigned int n = ACE_OS::atoi(ent->d_name + 10);
        DDS_Dirent overflow(file.c_str());
        scan_dir(ent->d_name, overflow, n);

      } else if (ACE_OS::strlen(ent->d_name) <= FSS_MAX_FILE_NAME_ENCODED) {
        dirs_[b32h_decode(ent->d_name)] = phys;
        ++overflow_[overflow_index];

      } else {
        CwdGuard cg(file);
        std::ifstream fn("_fullname");
        std::string fullname;

        if (!std::getline(fn, fullname)) {
          throw std::runtime_error("Can't read .../_fullname");
        }

        ACE_TString full_t(ACE_TEXT_CHAR_TO_TCHAR(fullname.c_str()));
        dirs_[full_t] = phys;
        ++overflow_[overflow_index];

        String_Index_t idx = phys.rfind(ACE_TEXT('.'));

        if (idx == ACE_TString::npos) {
          throw std::runtime_error("Badly formatted long dir name");
        }

        ACE_TString prefix(phys.c_str(), idx);
        unsigned int serial = ACE_OS::atoi(&phys[idx + 1]);
        unsigned int& counter = long_names_[prefix];

        if (serial >= counter) counter = serial + 1;
      }

    } else { // regular file
      if (ent->d_name[0] != ACE_TEXT('_')) {
        files_[b32h_decode(ent->d_name)] = ent->d_name;
        ++overflow_[overflow_index];
      }
    }
  }
}
int main(int argc, const char **argv) {
	seed();

	physics::settings_type physics_settings;
	scene::settings_type scene_settings;
	Helix::settings_type helix_settings;

	std::string input_file, output_file;
	parse_settings::parse(argc, argv, physics_settings, scene_settings, helix_settings, input_file, output_file);

	if (input_file.empty() || output_file.empty() || argc < 3) {
		std::cerr << parse_settings::usage(argv[0]) << std::endl;
		return 0;
	}

	scene mesh(scene_settings, helix_settings);
	physics phys(physics_settings);

	try {
		if (!mesh.read(phys, input_file)) {
			std::cerr << "Failed to read scene \"" << input_file << "\"" << std::endl;
			return 1;
		}
	}
	catch (const std::runtime_error & e) {
		std::cerr << "Failed to read scene \"" << input_file << "\": " << e.what() << std::endl;
		return 1;
	}

	physics::real_type initialmin, initialmax, initialaverage, initialtotal, min, max, average, total;
	mesh.getTotalSeparationMinMaxAverage(initialmin, initialmax, initialaverage, initialtotal);

	std::cerr << "Running simulation for scene loaded from \"" << input_file << " outputting to " << output_file << "\"." << std::endl
		<< "Initial: min: " << initialmin << ", max: " << initialmax << ", average: " << initialaverage << ", total: " << initialtotal << " nm" << std::endl
		<< "Connect with NVIDIA PhysX Visual Debugger to " << PVD_HOST << ':' << PVD_PORT << " to visualize the progress. " << std::endl
		<< "Press ^C to stop the relaxation...." << std::endl;

	setinterrupthandler<handle_exit>();

	SceneDescription best_scene;

	Helix helix1 = Helix(helix_settings, phys, 20, physics::transform_type(physics::vec3_type(1,20,1)));
	Helix helix2 = Helix(helix_settings, phys, 20, physics::transform_type(physics::vec3_type(1, 20, 8)));
	helix1.attach(phys, helix2, Helix::AttachmentPoint::kBackwardFivePrime, Helix::AttachmentPoint::kBackwardThreePrime);

#if 0
	best_scene = simulated_rectification(mesh, phys, []() { return running; });
#else
#if 0
	simulated_annealing(mesh, phys, 100, 0, 7, 1,
		[&best_scene](scene & mesh, float e) { std::cerr << "Store best energy: " << e << std::endl; best_scene = SceneDescription(mesh); },
		[]() { return running; });
#else
	gradient_descent(mesh, phys, 7,
		[&best_scene, &min, &max, &average, &total](scene & mesh, physics::real_type min_, physics::real_type max_, physics::real_type average_, physics::real_type total_) { min = min_; max = max_; average = average_; total = total_; std::cerr << "State: min: " << min << ", max: " << max << ", average: " << average << " total: " << total << " nm" << std::endl; best_scene = SceneDescription(mesh); },
		[]() { return running; });
#endif
#endif

	std::cerr << "Result: min: " << min << ", max: " << max << ", average: " << average << ", total: " << total << " nm" << std::endl;

	{
		std::ofstream outfile(output_file);
		outfile << "# Relaxation of original " << input_file << " file. " << mesh.getHelixCount() << " helices." << std::endl
			<< "# Total separation: Initial: min: " << initialmin << ", max: " << initialmax << ", average: " << initialaverage << ", total: " << initialtotal << " nm" << ", final: min: " << min << ", max: " << max << ", average: " << average << ", total: " << total << " nm" << std::endl;

		if (!best_scene.write(outfile))
			std::cerr << "Failed to write resulting mesh to \"" << output_file << "\"" << std::endl;

		outfile.close();
	}

	sleepms(2000);

	return 0;
}
Example #9
0
void display(void){
	phys();
	keyboard();
	joystick();

	glClearColor(0.28, 0.32, 0.95, 1.0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	if (v.shader) v.shader->begin();
	GLint ticks = glGetUniformLocation(v.programObject, "ticks");
	if (ticks != -1)
	{
		glUniform1f(ticks, v.cm->framecount);
	}

	GLint lightSources = glGetUniformLocation(v.programObject, "lightSources");
	if (lightSources != -1)
	{
		v.lightSS[0] = 1220;
		v.lightSS[10] = 55;
		v.lightSS[20] = 760;
		v.lightSS[30] = 10;

		v.lightSS[1] = 1216;
		v.lightSS[11] = 56;
		v.lightSS[21] = 778;
		v.lightSS[31] = 15;

		v.lightSS[2] = 1116;
		v.lightSS[12] = 56;
		v.lightSS[22] = 778;
		v.lightSS[32] = 50;

		v.lightSS[3] = 1195;
		v.lightSS[13] = 48;
		v.lightSS[23] = 778;
		v.lightSS[33] = 4;
		glUniform1fv(lightSources, 40, v.lightSS);
	}

	v.cam->look();

	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);
	glDepthMask(GL_TRUE);
	//glDisable(GL_BLEND);
	glEnable(GL_BLEND);
	glPolygonMode(GL_FRONT, GL_FILL);
	
	//glEnable(GL_TEXTURE_2D);
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, v.atlas);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

	v.cm->frame(v.cam);
	//glDisable(GL_TEXTURE_2D);

	if (v.shader) v.shader->end();

	v.rt = RayTrace::trace(v.cam, v.cm);
	if (v.rt.target != NULL && v.rt.target->type != AIR){
		glPushMatrix();
		glTranslatef(Block::RENDER_SIZE * v.rt.tx + Block::RENDER_SIZE / 2.0f, Block::RENDER_SIZE * v.rt.ty + Block::RENDER_SIZE / 2.0f, Block::RENDER_SIZE * v.rt.tz + Block::RENDER_SIZE / 2.0f);
		glColor3f(0, 0, 0);
		glLineWidth(2);
		glutWireCube(Block::RENDER_SIZE + 0.005);
		glPopMatrix();
	}

	glPushMatrix();
	glClear(GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();
	glTranslatef(0, 0, -0.5f);
	glColor3f(0, 0, 0);
	float size = 0.01f;
	glLineWidth(2);
	glBegin(GL_LINES);
	glVertex3f(-size, 0, 0);
	glVertex3f(size, 0, 0);
	glVertex3f(0, -size, 0);
	glVertex3f(0, size, 0);
	glEnd();
	glPopMatrix();

	glPushMatrix();
	glLoadIdentity();
	glTranslatef(0, 0.4f, -0.5f);
	glColor3f(1, 1, 1);
	float texsize = 0.06f;
	glBegin(GL_QUADS);
	glTexCoord2f(tx(v.t, TOP), ty(v.t, TOP));
	glVertex3f(-texsize, -texsize, 0);
	glTexCoord2f(tx(v.t, TOP) + 1.0f / 16.0f, ty(v.t, TOP));
	glVertex3f(texsize, -texsize, 0);
	glTexCoord2f(tx(v.t, TOP) + 1.0f / 16.0f, ty(v.t, TOP) + 1.0f / 16.0f);
	glVertex3f(texsize, texsize, 0);
	glTexCoord2f(tx(v.t, TOP), ty(v.t, TOP) + 1.0f / 16.0f);
	glVertex3f(-texsize, texsize, 0);
	glEnd();
	glPopMatrix();
}