int main()
{
	orwell::support::GlobalLogger::Create("test_agent", "test_agent.log", true);
	log4cxx::NDC ndc("test_agent");
	ORWELL_LOG_INFO("Test starts\n");

	orwell::Application::CommandLineParameters aCommandLineArguments;
	aCommandLineArguments.m_agentPort = 9004;
	aCommandLineArguments.m_tickInterval = 1;
	aCommandLineArguments.m_gameDuration = 100;
	aCommandLineArguments.m_dryRun = false;
	aCommandLineArguments.m_broadcast = false;

	orwell::Application::Parameters aParameters;
	Arguments aArguments = Common::GetArguments(
			aCommandLineArguments,
			true);
	orwell::Application::ReadParameters(
			aArguments.m_argc,
			aArguments.m_argv,
			aParameters);
	TestAgent aTestAgent(aParameters.m_commandLineParameters.m_agentPort.get());
	std::thread aApplicationThread(Application, aParameters);
	aTestAgent.sendCommand("stop application");
	aApplicationThread.join();
	orwell::support::GlobalLogger::Clear();
	return 0;
}
Exemple #2
0
TagIterator::~TagIterator ()
{
  saml::NDC ndc("~TagIterator");
  ini->iterators--;
  ini->rwlock->unlock();
  ini->log->debug("iterators: %d", ini->iterators);
}
PxVec3 CameraComponent::worldToScreenPoint(const PxVec3& position) const
{
	PxVec4 clip = m_camera.getViewProjection().transform(PxVec4(position, 1.0));
	PxVec3 ndc(clip.x / clip.w, clip.y / clip.w, clip.z / clip.w);
	PxVec2 screenDim((PxReal)getCoreEngine()->getViewport()->getScreenWidth(), (PxReal)getCoreEngine()->getViewport()->getScreenHeight());
	return PxVec3((screenDim.x / 2.0f) * ndc.x + (screenDim.x / 2.0f), screenDim.y - ((screenDim.y / 2.0f) * ndc.y + (screenDim.y / 2.0f)), clip.z);
}
Exemple #4
0
HeaderIterator::HeaderIterator (ShibINIPriv* inip)
{
  saml::NDC ndc("HeaderIterator");
  ini = inip;
  valid = false;
  ini->rwlock->rdlock();
  ini->iterators++;
  ini->log->debug("iterators: %d", ini->iterators);
}
Exemple #5
0
TagIterator::TagIterator (ShibINIPriv* inip, const string& headerp)
  : header(headerp)
{
  saml::NDC ndc("TagIterator");
  ini = inip;
  valid = false;
  ini->rwlock->rdlock();
  ini->iterators++;
  ini->log->debug("iterators: %d", ini->iterators);
}
Exemple #6
0
void DrawLines::eventDraw(Event* event){
    if (!drawModeEnabled_)
        return;

    auto mouseEvent = static_cast<MouseEvent*>(event);
    auto line = mouseEvent->ndc();

    addPoint(vec2(line.x, line.y));
    invalidate(InvalidationLevel::InvalidOutput);
}
oglplus::Vec3f SpectraDocumentView::ScreenToWorld(GLint x, GLint y)
{
	GLfloat u = -1.0f+GLfloat(2*x)/GLfloat(width);
	GLfloat v = +1.0f-GLfloat(2*y)/GLfloat(height);
	GLfloat w = 1.0f;

	oglplus::Vec4f ndc(u, v, w, 1.0f);

	oglplus::Vec4f wsc = inv_view_matrix * ndc;

	return wsc.xyz() / wsc.w();
}
Exemple #8
0
		virtual void run() {
			long i = 0;
			while (true) {
				ENDC ndc("abc");
				EMDC mdc("x1", "v1");
				mdc.put("x2", "v2");

				ELOG_I(logger, "i=%d", i++);
				ELOG_W(logger, "i=%d", i++);
				ELOG_E(logger, "i=%d", i++);

				EThread::sleep(100);
			}
		}
Exemple #9
0
bool ViewDepthCull::cullByDepth(const Vector3F & pnt, const float & threshold,
					float & camZ) const
{
	Vector3F camP = cameraInvSpace().transform(pnt);
	camZ = camP.z;
	if(camZ > -1.f) {
		camZ = -1.f;
		return false;
	}
	float s, t;
	ndc(camP, s, t);
	
	float b = m_depthCuller->getBufferDepth(s, t);
	if(b<1.f) return false;
	return (-camZ - threshold * 4.f) > b;
}
int main()
{
	orwell::support::GlobalLogger::Create(
			"test_stop_after_game_duration",
			"test_stop_after_game_duration.log",
			true);
	log4cxx::NDC ndc("test_main_plus");
	ORWELL_LOG_INFO("Test starts\n");

	std::thread aApplicationThread(Application);
	std::thread aAgentThread(Stopper);
	aApplicationThread.join();
	aAgentThread.join();
	orwell::support::GlobalLogger::Clear();
	return g_status;
}
Exemple #11
0
        Vector2 Camera::projectPoint(const Vector3& src) const
        {
            Vector2 screenPos;

            auto viewport = sharedEngine->getRenderer()->getSize();
            Vector4 clipPos;

            getViewProjection().transformVector(Vector4(src.x, src.y, src.z, 1.0f), clipPos);

            assert(clipPos.w != 0.0f);
            Vector2 ndc(clipPos.x / clipPos.w, clipPos.y / clipPos.w);

            screenPos.x = (ndc.x + 1.0f) * 0.5f * viewport.width;
            screenPos.y = (ndc.y + 1.0f) * 0.5f * viewport.height;

            return screenPos;
        }
Exemple #12
0
Ray::Ray(const gfx::View* view, const gfx::ICamera* camera, const vec2& mousePos, float maxDist /*= FLT_MAX*/ )
{
    const RectI& viewPort(view->getViewport());
    vec2 ndc(((mousePos.x - viewPort.x) / viewPort.width) * 2.0f - 1.0f,
             -((mousePos.y - viewPort.y ) / viewPort.height) * 2.0f + 1.0f);
    vec4 nearPoint(ndc, 0.0f, 1.0f);
    vec4  farPoint(ndc, 1.0f, 1.0f);

    mat44 unproject(camera->getViewProjection().inverse());

    nearPoint = unproject * nearPoint;
    farPoint = unproject * farPoint;

    m_Origin = nearPoint.xyz() / nearPoint.w;
    m_Direction = normalize(farPoint.xyz() / farPoint.w - m_Origin);
    m_MaxDistance = maxDist;
}
Exemple #13
0
// Utils
// Some links: 
// ***** http://www.songho.ca/opengl/gl_transform.html 
// **  http://www.vb6.us/tutorials/using-mouse-click-3d-space-directx-8 
// *** http://www.mvps.org/directx/articles/rayproj.htm
// -------------------------------------------------------------------------
Vec3 Camera::screenToWorld(float nX, float nY, float nZ) {
	float mouse_x = nX;
	float mouse_y = nY;

	// @todo
	printf("ERROR in CAMERA: ofGetWidth(), ofGetHeight() cannot be used! pass as param!");
	float screen_w = 100;
	float screen_h = 200;
	
//	float screen_w = ofGetWidth();
//	float screen_h = ofGetHeight();
	float aspect = screen_w/screen_h;
	
	float ndx = -1.0f + (mouse_x/screen_w) * 2.0f; // left: -1, right: 1
	float ndy = (1.0f - (mouse_y/(screen_h * 0.5))); // top: -1, bottom: 1
	float ndz = 2.0*nZ-1.0;
	//ndz = nZ;
	updateViewMatrix(); 
	updateProjectionMatrix();

	Vec4 ndc(ndx, ndy, ndz, 1.0);
//	cout << "ndc cam:" << ndc << endl;
//	Mat4 mvp = mvm() * pm() ;
	Mat4 mvp = pm() * vm(); 
	mvp.inverse();
	ndc = mvp * ndc;
		
//	cout << "out cam:" << ndc << endl;
//	ndc = affine_inverse(mvp) * ndc;
//	cout << "@@@@@@@@@@@@@@@@@ cam @@@@@@@@@@@@@@@@@@@@@\n"; 
	//Mat4 inv = affine_inverse(mvp);
	//cout << inv;
//	cout << mvp ;
//	cout << "######################################\n\n"; 
	ndc.w = 1.0f / ndc.w;
	Vec3 r(ndc.x * ndc.w, ndc.y * ndc.w, ndc.z * ndc.w);
	
	return r;
}
Exemple #14
0
//
// Must be called holding the ReadLock.
//
void ShibINI::refresh(void)
{
  saml::NDC ndc("refresh");

  // check if we need to refresh
#ifdef _WIN32
  struct _stat stat_buf;
  if (_stat (m_priv->file.c_str(), &stat_buf) < 0)
#else
  struct stat stat_buf;
  if (stat (m_priv->file.c_str(), &stat_buf) < 0)
#endif
    m_priv->log->error("stat failed: %s", m_priv->file.c_str());

#ifdef DEBUG
  m_priv->log->info("refresh: last modtime at %d; file is %d; iters: %d",
		    m_priv->modtime, stat_buf.st_mtime, m_priv->iterators);
#endif

  if (m_priv->modtime >= stat_buf.st_mtime || m_priv->iterators > 0)
    return;

  // Release the read lock -- grab the write lock.  Don't worry if
  // this is non-atomic -- we'll recheck the status.
  m_priv->rwlock->unlock();
  m_priv->rwlock->wrlock();

  // Recheck the modtime
  if (m_priv->modtime >= stat_buf.st_mtime) {
    // Yep, another thread got to it.  We can exit now...  Release
    // the write lock and reaquire the read-lock.

    m_priv->rwlock->unlock();
    m_priv->rwlock->rdlock();
    return;
  }

  // Ok, we've got the write lock.  Let's update our state.

  m_priv->modtime = stat_buf.st_mtime;

  // clear the existing maps
  m_priv->table.clear();

  m_priv->log->info("reading %s", m_priv->file.c_str());
  
  // read the file
  try
  {
    ifstream infile (m_priv->file.c_str());
    if (!infile) {
      m_priv->log->warn("cannot open file: %s", m_priv->file.c_str());
      m_priv->rwlock->unlock();
      m_priv->rwlock->rdlock();
      return;
    }

    const int MAXLEN = 1024;
    char linebuffer[MAXLEN];
    string current_header;
    bool have_header = false;

    while (infile) {
      infile.getline (linebuffer, MAXLEN);
      string line (linebuffer);

      if (line[0] == '#') continue;

      trimline (line);
      if (line.size() <= 1) continue;

      if (line[0] == '[') {
	// this is a header

#ifdef DEBUG
	m_priv->log->info("Found what appears to be a header line");
#endif

	have_header = false;

	// find the end of the header
	int endpos = line.find (']');
	if (endpos == line.npos) {
#ifdef DEBUG
	  m_priv->log->info("Weird: no end found.. punting");
#endif
	  continue; // HUH?  No end?
	}

	// found it
	current_header = line.substr (1, endpos-1);
	trimline (current_header);

	if (!m_priv->cs) to_lowercase (current_header);

	m_priv->table[current_header] = map<string,string>();
	have_header = true;
#ifdef DEBUG
	m_priv->log->info("current header: \"%s\"", current_header.c_str());
#endif

      } else if (have_header) {
	// this is a tag

#ifdef DEBUG
	m_priv->log->info("Found what appears to be a tag line");
#endif

	string tag, setting;
	int mid = line.find ('=');

	if (mid == line.npos) {
#ifdef DEBUG
	  m_priv->log->info("Weird: no '=' found.. punting");
#endif
	  continue; // Can't find the value's setting
	}

	tag = line.substr (0,mid);
	setting = line.substr (mid+1, line.size()-mid);

	trimline (tag);
	trimline (setting);

	if (!m_priv->cs) to_lowercase (tag);

	// If it already exists, log an error and do not save it
	if (m_priv->exists (current_header, tag))
	  m_priv->log->error("Duplicate tag found in section %s: \"%s\"",
			     current_header.c_str(), tag.c_str());
	else
	  (m_priv->table[current_header])[tag] = setting;

#ifdef DEBUG
	m_priv->log->info("new tag: \"%s\" = \"%s\"",
			  tag.c_str(), setting.c_str());
#endif

      }

    } // until the file ends

  } catch (...) {
    // In case there are exceptions.
  }

  // Now release the write lock and reaquire the read lock
  m_priv->rwlock->unlock();
  m_priv->rwlock->rdlock();
}
Exemple #15
0
int RenderCore::step(Rand& rand, int groupIdx)
{
	const Camera* active_camera = &camera;

	float4x4 inv_view = glm::inverse(active_camera->view());
	float4x4 inv_proj = glm::inverse(active_camera->projection());
	float3 o = active_camera->eye;
		
    int samples_n = 0;
	bool clear = clearSignal_[groupIdx];
	for(int i = 0; i < size_.y; i++)
	{
		if((i % cachedWorkThreadN_) != groupIdx) continue;
		for(int j = 0; j < size_.x; j++)
		{
            int fb_i = i * size_.x + j;			

			Sample sample;
			sample.reset();
			
			if(clear)
			{
				linear_fb[fb_i] = float4(0);
			}
				
			float2 pixel_pos(j, i);			
			float2 sample_pos = pixel_pos + float2(rand.next01(), rand.next01());					
			float4 ndc((sample_pos.x/size_.x-0.5)*2, (sample_pos.y/size_.y-0.5)*2, 1, 1);
			float4 d_comp = inv_proj * ndc;
			d_comp = d_comp/d_comp.w;
			d_comp = inv_view * d_comp;
			float3 d = normalize(float3(d_comp));
			Ray ray(o, d);

			sample.ray = ray;
			sample.xy = int2(j, i);
			
			sampleDebugger_.shr.newSample(sample.xy);
			
			int bounces = 8 ;
			if(1)
			{
				ptMISRun(*scene, bounces, rand, &sample, false);
			}
			else if(0)
			{
				ptRun(*scene, bounces, rand, &sample, false);
			}
			else if(0)
			{
				bdptRun(*scene, bounces, rand, &sample);
			}
			else 
			{
				bdptMisRun(*scene, bounces, active_camera->forward, rand, &sample);
			}
			

			samples_n += 1;
			float3 color = sample.radiance;
			sampleDebugger_.shr.record(sample.xy, 7, "Radiance", color);
			
			float3 existing_color = float3(linear_fb[fb_i]);
			sampleDebugger_.shr.record(sample.xy, 7, "Existing Mix", existing_color);
			float samples_count = linear_fb[fb_i].w + 1;

			float3 mixed_color = float3((samples_count - 1) / samples_count) * existing_color + 
				float3(1/samples_count) * color;
			sampleDebugger_.shr.record(sample.xy, 7, "New Mix", mixed_color);
			linear_fb[fb_i] = float4(mixed_color, samples_count);
			
		}
	}
	//we don't clear unconditionally b/c clear may have been enabled since we last checked
	if(clear) clearSignal_[groupIdx] = false;
    return samples_n;
}
Exemple #16
0
int main( int argc, char* argv[]) {
  if(argc != 2) {
    std::cerr << "Usage : ./main.out <edge_file>" << std::endl;
    exit(1);
  }

  Network network;
  std::ifstream fin(argv[1]);
  std::cerr << "Loading input file" << std::endl;
  network.LoadFile( fin );

  bool is_weighted = network.IsWeighted();
  if( ! is_weighted ) {
    std::cerr << "All the link weights are 1. Analyze the network as a non-weighted network." << std::endl;
  }

  std::pair<double,double> fc;
  if( is_weighted ) {
  std::cerr << "Conducting percolation analysis" << std::endl;
  std::ofstream lrp("link_removal_percolation.dat");
  lrp << "#fraction  weak_link_removal_lcc susceptibility strong_link_removal_lcc susceptibility" << std::endl;
  fc = network.AnalyzeLinkRemovalPercolationVariableAccuracy( 0.02, 0.005, lrp );
  lrp.flush();
  }

  std::cerr << "Calculating local clustering coefficients" << std::endl;
  network.CalculateLocalCCs();
  if( is_weighted ) {
  std::cerr << "Calculating overlaps" << std::endl;
  network.CalculateOverlaps();
  }

  std::cerr << "Calculating degree distribution" << std::endl;
  std::ofstream dd("degree_distribution.dat");
  const auto degree_distribution = network.DegreeDistribution();
  for(const auto& f : degree_distribution ) {
    dd << f.first << ' ' << f.second << std::endl;
  }
  dd.flush();

  if( is_weighted ) {
  std::cerr << "Calculating link weight distribution" << std::endl;
  // double edge_weight_bin_size = 1.0;
  std::ofstream ewd("edge_weight_distribution.dat");
  for(const auto& f : network.EdgeWeightDistributionLogBin() ) {
    ewd << f.first << ' ' << f.second << std::endl;
  }
  ewd.flush();
  }

  std::map<double, size_t> strength_distribution;
  if( is_weighted ) {
  std::cerr << "Calculating node strength distribution" << std::endl;
  double avg_s = network.AverageEdgeWeight() * network.AverageDegree();
  double strength_bin_size = avg_s * 0.01;
  std::ofstream sd("strength_distribution.dat");
  strength_distribution = network.StrengthDistribution(strength_bin_size);
  for(const auto& f :strength_distribution) {
    sd << f.first << ' ' << f.second << std::endl;
  }
  sd.flush();
  }

  std::cerr << "Calculating c(k)" << std::endl;
  std::ofstream cc_d("cc_degree_correlation.dat");
  for(const auto& f : network.CC_DegreeCorrelation() ) {
    cc_d << f.first << ' ' << f.second << std::endl;
  }
  cc_d.flush();

  if( is_weighted ) {
  std::cerr << "Calculating s(k)" << std::endl;
  std::ofstream sdc("strength_degree_correlation.dat");
  for(const auto& f : network.StrengthDegreeCorrelation() ) {
    sdc << f.first << ' ' << f.second << std::endl;
  }
  sdc.flush();
  }

  std::cerr << "Calculating k_nn(k)" << std::endl;
  std::ofstream ndc("neighbor_degree_correlation.dat");
  for(const auto& f : network.NeighborDegreeCorrelation() ) {
    ndc << f.first << ' ' << f.second << std::endl;
  }
  ndc.flush();

  if( is_weighted ) {
  std::cerr << "Calculating O(w)" << std::endl;
  std::ofstream owc("overlap_weight_correlation.dat");
  for(const auto& f : network.OverlapWeightCorrelationLogBin() ) {
    owc << f.first << ' ' << f.second << std::endl;
  }
  owc.flush();
  }

  std::cerr << "Calculating scalar values" << std::endl;
  std::ofstream fout("_output.json");
  fout << "{" << std::endl;
  fout << "  \"NumNodes\": " << network.NumNodes() << ',' << std::endl;
  fout << "  \"NumEdges\": " << network.NumEdges() << ',' << std::endl;
  fout << "  \"AverageDegree\": " << network.AverageDegree() << ',' << std::endl;
  fout << "  \"Assortativity\": " << network.PCC_k_knn() << ',' << std::endl;
  fout << "  \"ArgMax_Pk\": " << ArgMax( degree_distribution ) << ',' << std::endl;
  fout << "  \"ClusteringCoefficient\": " << network.ClusteringCoefficient() << ',' << std::endl;
  fout << "  \"PCC_C_k\": " << network.PCC_C_k();
  if( is_weighted ) {
  fout << ',' << std::endl;
  double ave_w = network.AverageEdgeWeight();
  fout << "  \"AverageEdgeWeight\": " << ave_w << ',' << std::endl;
  double ave_k = network.AverageDegree();
  fout << "  \"AverageStrength\": " << ave_w * ave_k << ',' << std::endl;
  double argmax_ps = ArgMax( strength_distribution );
  fout << "  \"ArgMax_Ps\": " << argmax_ps << ',' << std::endl;
  fout << "  \"Normalized_ArgMax_Ps\": " << argmax_ps / (ave_w*ave_k) << ',' << std::endl;
  fout << "  \"PCC_s_k\": " << network.PCC_s_k() << ',' << std::endl;
  fout << "  \"AverageOverlap\": " << network.AverageOverlap() << ',' << std::endl;
  fout << "  \"PCC_O_w\": " << network.PCC_O_w() << ',' << std::endl;
  fout << "  \"Fc_Ascending\": " << fc.first << ',' << std::endl;
  fout << "  \"Fc_Descending\": " << fc.second << ',' << std::endl;
  fout << "  \"Delta_Fc\": " << fc.second - fc.first << std::endl;
  }
  fout << "}" << std::endl;
  return 0;
}
Exemple #17
0
int main(int argc, char** argv)
{
    log4cxx::PropertyConfigurator::configure("logger.conf");
    Util::SyncHandler spipe(SIGPIPE, [](int, siginfo_t *, void *){;});

    po::options_description desc("Program options");
    desc.add_options()
    ("help,h", "show usage information")
    ("port", po::value<int>(&opt_port), "bind port (2080)")
    ("perf", po::bool_switch(&opt_perf), "turn off logging")
    ;
    //("coro", po::bool_switch(&opt_coro), "enable coro server")
    //("time", po::value<int>(&opt_time), "time to perform call, us (250000)")
    //("threads", po::value<int>(&opt_threads), "number of worker threads (no threads)")

    po::variables_map vm;
    try {
        po::store(po::parse_command_line(argc, argv, desc), vm);
    } catch (const std::exception& e) {
        ERROR(e.what());
        return -1;
    }
    po::notify(vm);
    if (vm.count("help")) {
        std::cout << desc << std::endl;
        return 0;
    }

    Server s;
    RPC::Library impl(s);

    boost::asio::io_service io;
    Util::ThreadGroup tg;

    boost::asio::signal_set signals(io, SIGINT, SIGTERM);
    signals.async_wait([&io](auto error, auto number){
        if (!error)
        {
            INFO("terminating server");
            io.stop();
        }
    });

    Util::Server server(io);
    server.run(opt_port, [&impl](boost::asio::streambuf& data, Util::FramedSocket ptr) {
        cbor::binary result;
        impl.process(data.data(), result);
        Util::FramedMessage reply(std::move(result));
        ptr->write(std::move(reply));
    });

    // start event loop
    tg.run([&io](){
        log4cxx::NDC ndc("server");
        TRACE("starting ... ");
        io.run();
        TRACE("terminated");
    });

    if (opt_perf)
        logger->setLevel(log4cxx::Level::getFatal());

    tg.wait();

    return 0;
}