예제 #1
0
std::vector<size_t> PathAligner::computeBaseDepth( char **seqs )
{
    int plen = (int)sequence.size();
    std::vector<size_t> depths(plen,0);

    //std::cout << "plen:" << plen << "\n";
    //std::cout << sequence << "\n";
    ReadPlacementList::iterator it;
    for ( it = places.begin(); it != places.end(); ++it ) {
        ReadPlacement place = *it;
        ReadId rid = place.rid;
        int rpos = place.read_pos;
        int ppos = place.path_pos;
        //int alen = place.length;
        
        //std::cout << "rid:" << rid << " rpos:" << rpos << " ppos:" << ppos << " alen:" << alen << "\n";
        std::string rseq = seqs[rid];
        //std::cout << "seq:" << rseq << "\n";
        int rlen = (int)rseq.size();
        int i,k;
        //for ( i=rpos,k=0; i<alen && k<plen; i++,k++ ) {
        for ( i=rpos,k=0; i<rlen && k<plen; i++,k++ ) {
            //if ( i >= rlen ) break;
            if ( k+ppos >= plen ) break;
            depths[k+ppos]++;
        }
    }
    return depths;
}
예제 #2
0
int tri_grid::get_max_level(void)
{
	std::vector<int> depths(triangles.size());
	for (unsigned int tri=0; tri<triangles.size(); tri++)
		depths[tri] = triangles[tri]->get_max_level();
	std::sort(depths.begin(), depths.end());
	return depths[triangles.size()-1];
}
예제 #3
0
	void Render(ExampleClock& clock)
	{
		positions.clear();
		ages.clear();

		// update the emitters and get the particle data
		for(auto i=emitters.begin(), e=emitters.end(); i!=e; ++i)
		{
			i->Update(clock);
			i->Upload(positions, ages);
		}
		assert(positions.size() == ages.size());

		// make a camera matrix
		auto cameraMatrix = CamMatrixf::Orbiting(
			Vec3f(),
			38.0 - SineWave(clock.Now().Seconds() / 6.0) * 17.0,
			FullCircles(clock.Now().Seconds() * 0.1),
			Degrees(SineWave(clock.Now().Seconds() / 20.0) * 60)
		);

		std::vector<float> depths(positions.size());
		std::vector<GLuint> indices(positions.size());
		// calculate the depths of the particles
		for(GLuint i=0, n=positions.size(); i!=n; ++i)
		{
			depths[i] = (cameraMatrix * Vec4f(positions[i], 1.0)).z();
			indices[i] = i;
		}

		// sort the indices by the depths
		std::sort(
			indices.begin(),
			indices.end(),
			[&depths](GLuint i, GLuint j)
			{
				return depths[i] < depths[j];
			}
		);

		// upload the particle positions
		pos_buf.Bind(Buffer::Target::Array);
		Buffer::Data(Buffer::Target::Array, positions, BufferUsage::DynamicDraw);
		// upload the particle ages
		age_buf.Bind(Buffer::Target::Array);
		Buffer::Data(Buffer::Target::Array, ages, BufferUsage::DynamicDraw);

		gl.Clear().ColorBuffer().DepthBuffer();
		camera_matrix.Set(cameraMatrix);
		// use the indices to draw the particles
		gl.DrawElements(
			PrimitiveType::Points,
			indices.size(),
			indices.data()
		);
	}
예제 #4
0
파일: PortionDrawer.cpp 프로젝트: 8l/oovcde
std::vector<size_t> PortionDrawer::getCallDepths() const
    {
    std::vector<size_t> depths(mGraph->getNodes().size());
    size_t initIndex = NO_INDEX;
    std::fill(depths.begin(), depths.end(), initIndex);
    for(size_t ni=0; ni<mGraph->getNodes().size(); ni++)
        {
        fillDepths(ni, depths);
        }
    return depths;
    }
예제 #5
0
파일: depths.cpp 프로젝트: xiaomo/Yamabiko
cv::Mat depths::load(const std::string &path, const cv::Size &size) {
    std::ifstream file(path.c_str());
    cv::Mat depths(size, CV_32F, -1.0);
    for (int i = 0, m = size.height; i < m; i++) {
        for (int j = 0, n = size.width; j < n; j++) {
            file >> depths.at<Depth>(i, j);
        }
    }

    return depths;
}
예제 #6
0
vector<DepthMinMax> getDistancesFromSOM(const NGHolder &g_orig) {
    // We operate on a temporary copy of the original graph here, so we don't
    // have to mutate the original.
    NGHolder g;
    ue2::unordered_map<NFAVertex, NFAVertex> vmap; // vertex in g_orig to vertex in g
    cloneHolder(g, g_orig, &vmap);

    vector<NFAVertex> vstarts;
    for (auto v : vertices_range(g)) {
        if (is_virtual_start(v, g)) {
            vstarts.push_back(v);
        }
    }
    vstarts.push_back(g.startDs);

    // wire the successors of every virtual start or startDs to g.start.
    for (auto v : vstarts) {
        wireSuccessorsToStart(g, v);
    }

    // drop the in-edges of every virtual start so that they don't participate
    // in the depth calculation.
    for (auto v : vstarts) {
        clear_in_edges(v, g);
    }

    //dumpGraph("som_depth.dot", g.g);

    vector<DepthMinMax> temp_depths; // numbered by vertex index in g
    calcDepthsFrom(g, g.start, temp_depths);

    // Transfer depths, indexed by vertex index in g_orig.
    vector<DepthMinMax> depths(num_vertices(g_orig));

    for (auto v_orig : vertices_range(g_orig)) {
        assert(contains(vmap, v_orig));
        NFAVertex v_new = vmap[v_orig];

        u32 orig_idx = g_orig[v_orig].index;

        DepthMinMax &d = depths.at(orig_idx);

        if (v_orig == g_orig.startDs || is_virtual_start(v_orig, g_orig)) {
            // StartDs and virtual starts always have zero depth.
            d = DepthMinMax(0, 0);
        } else {
            u32 new_idx = g[v_new].index;
            d = temp_depths.at(new_idx);
        }
    }

    return depths;
}
예제 #7
0
bool TCompiler::checkCallDepth()
{
    std::vector<int> depths(mCallDag.size());

    for (size_t i = 0; i < mCallDag.size(); i++)
    {
        int depth = 0;
        auto &record = mCallDag.getRecordFromIndex(i);

        for (auto &calleeIndex : record.callees)
        {
            depth = std::max(depth, depths[calleeIndex] + 1);
        }

        depths[i] = depth;

        if (depth >= maxCallStackDepth)
        {
            // Trace back the function chain to have a meaningful info log.
            infoSink.info.prefix(EPrefixError);
            infoSink.info << "Call stack too deep (larger than " << maxCallStackDepth
                          << ") with the following call chain: " << record.name;

            int currentFunction = static_cast<int>(i);
            int currentDepth = depth;

            while (currentFunction != -1)
            {
                infoSink.info << " -> " << mCallDag.getRecordFromIndex(currentFunction).name;

                int nextFunction = -1;
                for (auto& calleeIndex : mCallDag.getRecordFromIndex(currentFunction).callees)
                {
                    if (depths[calleeIndex] == currentDepth - 1)
                    {
                        currentDepth--;
                        nextFunction = calleeIndex;
                    }
                }

                currentFunction = nextFunction;
            }

            return false;
        }
    }

    return true;
}
예제 #8
0
파일: Driver.cpp 프로젝트: DavidMChan/hog2
void TestPruning(int depth, int bucket)
{
	RubikEdge e;
	RubiksCube c;
	RubiksState s;
	std::vector<uint64_t> depths(17);
	int count = 0;
	FILE *f = fopen(GetFileName(depth, bucket), "r");
	if (f == 0)
	{
		printf("Unable to open '%s'; aborting!\n", GetFileName(depth, bucket));
		return;
	}
	uint64_t next;
	while (fread(&next, sizeof(uint64_t), 1, f) == 1)
	{
		if (++count > 1000)
		{
			break;
		}
		printf("%d\r", count); fflush(stdout);
		uint64_t cornerRank;
		uint64_t edgeRank = next%e.getMaxSinglePlayerRank();
		cornerRank = next/e.getMaxSinglePlayerRank();
		cornerRank = cornerRank*kNumBuckets + bucket;
		//printf("%2d): Expanding %llu %llu\n", depth, x, next);
		c.GetStateFromHash(cornerRank, edgeRank, s);
		
		depths[c.Edge12PDBDist(s)]++;
	}
	fclose(f);
	printf("\n\n");
	for (int x = 0; x < depths.size(); x++)
	{
		printf("%d\t%llu\n", x, depths[x]);
	}
}
예제 #9
0
파일: Tfm.cpp 프로젝트: bngabonziza/miktex
void
Tfm::Read ()
{
  if (! dviChars.empty() || dviInfo.notLoadable)
    {
      return;
    }

  trace_tfm->WriteFormattedLine
    ("libdvi",
     T_("going to load TFM file %s"),
     dviInfo.name.c_str());

  PathName fileName;

  bool tfmFileExists =
    SessionWrapper(true)->FindTfmFile(dviInfo.name.c_str(),
				      fileName,
				      false);

  if (! tfmFileExists)
    {
      if (Make(dviInfo.name))
	{
	  tfmFileExists =
	    SessionWrapper(true)->FindTfmFile(dviInfo.name.c_str(),
					      fileName,
					      false);
	  if (! tfmFileExists)
	    {
	      // this shouldn't happen; but it does (#521481)
	    }
	}
      if (! tfmFileExists)
	{
	  dviInfo.transcript += "\r\n";
	  dviInfo.transcript += T_("Loading 'cmr10' instead.\r\n");
	  trace_error->WriteFormattedLine
	    ("libdvi",
	     T_("'%s' not loadable - loading 'cmr10' instead!"),
	     dviInfo.name.c_str());
	  if (! (SessionWrapper(true)->FindTfmFile("cmr10",
						   fileName,
						   false)
		 || (Make("cmr10")
		     && SessionWrapper(true)->FindTfmFile("cmr10",
							  fileName,
							  false))))
	    {
	      dviInfo.transcript += T_("'cmr10' not loadable either!");
	      trace_error->WriteLine
		("libdvi",
		 T_("'cmr10' not loadable - will display blank chars!"));
	      return;
	    }
	}
    }

  dviInfo.fileName = fileName.ToString();

  trace_tfm->WriteFormattedLine
    ("libdvi",
     T_("opening TFM file %s"),
     fileName.Get());

  InputStream inputStream (fileName.Get());

  long lf = inputStream.ReadSignedPair();

  if (lf == 0)
    {
      FATAL_DVI_ERROR ("Tfm::Read",
		       T_("Invalid TFM file."),
		       0);
    }

  long lh = inputStream.ReadSignedPair();
  long bc = inputStream.ReadSignedPair();
  long ec = inputStream.ReadSignedPair();
  long nw = inputStream.ReadSignedPair();
  long nh = inputStream.ReadSignedPair();
  long nd = inputStream.ReadSignedPair();
  long ni = inputStream.ReadSignedPair();
  long nl = inputStream.ReadSignedPair();
  long nk = inputStream.ReadSignedPair();
  long ne = inputStream.ReadSignedPair();
  long np = inputStream.ReadSignedPair();

  trace_tfm->WriteFormattedLine
    ("libdvi",
     T_("header size: %ld"),
     lh);

  trace_tfm->WriteFormattedLine
    ("libdvi",
     T_("smallest character code: %ld"),
     bc);

  trace_tfm->WriteFormattedLine
    ("libdvi",
     T_("largest character code: %ld"),
     ec);

  trace_tfm->WriteFormattedLine
    ("libdvi",
     T_("width table size: %ld"),
     nw);

  trace_tfm->WriteFormattedLine
    ("libdvi",
     T_("height table size: %ld"),
     nh);

  trace_tfm->WriteFormattedLine
    ("libdvi",
     T_("depth table size: %ld"),
     nd);

  trace_tfm->WriteFormattedLine
    ("libdvi",
     T_("italic correction table size: %ld"),
     ni);

  trace_tfm->WriteFormattedLine
    ("libdvi",
     T_("lig/kern table size: %ld"),
     nl);

  trace_tfm->WriteFormattedLine
    ("libdvi",
     T_("kern table size: %ld"),
     nk);

  trace_tfm->WriteFormattedLine
    ("libdvi",
     T_("extensible character table size: %ld"),
     ne);

  trace_tfm->WriteFormattedLine
    ("libdvi",
     T_("font parameter size: %ld"),
     np);

  int my_checkSum = inputStream.ReadSignedQuad();

  trace_tfm->WriteFormattedLine
    ("libdvi",
     "checkSum: 0%lo",
     my_checkSum);
  
  int my_designSize = inputStream.ReadSignedQuad();

  trace_tfm->WriteFormattedLine
    ("libdvi",
     "designSize: %ld",
     my_designSize);

  if (my_checkSum != checkSum)
    {
      trace_error->WriteFormattedLine
	("libdvi",
	 T_("%s: checkSum mismatch"),
	 dviInfo.name.c_str());
    }

  if (my_designSize * tfmConv != designSize)
    {
      trace_error->WriteFormattedLine
	("libdvi",
	 T_("%s: designSize mismatch"),
	 dviInfo.name.c_str());
    }

  inputStream.SkipBytes ((lh - 2) * 4);

  struct TfmIndex
  {
    int widthIndex;
    int heightIndex;
    int depthIndex;
  };

  vector<TfmIndex> infoTable (ec);

  for (int charCode = bc; charCode < ec; ++ charCode)
    {
      DviChar * pDviChar = new DviChar (this);
      dviChars[charCode] = pDviChar;
      pDviChar->SetCharacterCode (charCode);
      TfmIndex tfmIndex;
      tfmIndex.widthIndex = inputStream.ReadSignedByte();
      int heightDepth = inputStream.ReadSignedByte();
      tfmIndex.heightIndex = ((heightDepth >> 4) & 15);
      tfmIndex.depthIndex = (heightDepth & 15);
      inputStream.SkipBytes (2);
      infoTable[charCode] = tfmIndex;
    }

  vector<int> widths (nw);

  for (int idx = 0; idx < nw; ++ idx)
    {
      widths[idx] = inputStream.ReadSignedQuad();
    }

  vector<int> heights (nh);

  for (int idx = 0; idx < nh; ++ idx)
    {
      heights[idx] = inputStream.ReadSignedQuad();
    }

  vector<int> depths (nd);

  for (int idx = 0; idx < nd; ++ idx)
    {
      depths[idx] = inputStream.ReadSignedQuad();
    }

  // inputStream.Close ();

  for (int charCode = bc; charCode < ec; ++ charCode)
    {
      int tfmWidth =
	ScaleFix(widths[infoTable[charCode].widthIndex], GetScaledAt());
      dviChars[charCode]->SetDviWidth (tfmWidth);
      int pixelWidth;
      if (tfmWidth >= 0)
	{
	  pixelWidth = static_cast<int>(conv * tfmWidth + 0.5);
	}
      else
	{
	  pixelWidth = - static_cast<int>(conv * -tfmWidth + 0.5);
	}
      dviChars[charCode]->SetWidth (pixelWidth);
    }
}
예제 #10
0
bool
HdxIntersector::Query(HdxIntersector::Params const& params,
                      HdRprimCollection const& col,
                      HdEngine* engine,
                      HdxIntersector::Result* result)
{
    TRACE_FUNCTION();

    // Make sure we're in a sane GL state before attempting anything.
    if (GlfHasLegacyGraphics()) {
        TF_RUNTIME_ERROR("framebuffer object not supported");
        return false;
    }
    GlfGLContextSharedPtr context = GlfGLContext::GetCurrentGLContext();
    if (!TF_VERIFY(context)) {
        TF_RUNTIME_ERROR("Invalid GL context");
        return false;
    }
    if (!_drawTarget) {
        // Initialize the shared draw target late to ensure there is a valid GL
        // context, which may not be the case at constructon time.
        _Init(GfVec2i(128,128));
    }

    GfVec2i size(_drawTarget->GetSize());
    GfVec4i viewport(0, 0, size[0], size[1]);

    if (!TF_VERIFY(_renderPass)) {
        return false;
    }
    _renderPass->SetRprimCollection(col);

    // Setup state based on incoming params.
    _renderPassState->SetAlphaThreshold(params.alphaThreshold);
    _renderPassState->SetClipPlanes(params.clipPlanes);
    _renderPassState->SetCullStyle(params.cullStyle);
    _renderPassState->SetCamera(params.viewMatrix, params.projectionMatrix, viewport);
    _renderPassState->SetLightingEnabled(false);

    // Use a separate drawTarget (framebuffer object) for each GL context
    // that uses this renderer, but the drawTargets share attachments/textures.
    GlfDrawTargetRefPtr drawTarget = GlfDrawTarget::New(size);

    // Clone attachments into this context. Note that this will do a
    // light-weight copy of the textures, it does not produce a full copy of the
    // underlying images.
    drawTarget->Bind();
    drawTarget->CloneAttachments(_drawTarget);

    //
    // Setup GL raster state
    //

    GLenum drawBuffers[3] = { GL_COLOR_ATTACHMENT0,
                              GL_COLOR_ATTACHMENT1,
                              GL_COLOR_ATTACHMENT2 };
    glDrawBuffers(3, drawBuffers);
    
    glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE);
    glDisable(GL_BLEND);

    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);
    glDepthFunc(GL_LEQUAL);  

    glClearColor(0,0,0,0);
    glClearStencil(0);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);

    glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);

    GLF_POST_PENDING_GL_ERRORS();
    
    //
    // Execute the picking pass
    //
    {
        GLuint vao;
        glGenVertexArrays(1, &vao);
        glBindVertexArray(vao);
        // Setup stencil state and prevent writes to color buffer.
        glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
        glEnable(GL_STENCIL_TEST);
        glStencilFunc(GL_ALWAYS, 1, 1);
        glStencilOp(GL_KEEP,     // stencil failed
                    GL_KEEP,     // stencil passed, depth failed
                    GL_REPLACE); // stencil passed, depth passed

        //
        // Condition the stencil buffer.
        //
        params.depthMaskCallback();
        // we expect any GL state changes are restored.

        // Disable stencil updates and setup the stencil test.
        glStencilFunc(GL_LESS, 0, 1);
        glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
        // Clear depth incase the depthMaskCallback pollutes the depth buffer.
        glClear(GL_DEPTH_BUFFER_BIT);
        // Restore color outputs & setup state for rendering
        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
        glDisable(GL_CULL_FACE);
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
        glFrontFace(GL_CCW);

        //
        // Enable conservative rasterization, if available.
        //
        // XXX: This wont work until it's in the Glew build.
        bool convRstr = glewIsSupported("GL_NV_conservative_raster");
        if (convRstr) {
            // XXX: this should come from Glew
            #define GL_CONSERVATIVE_RASTERIZATION_NV 0x9346
            glEnable(GL_CONSERVATIVE_RASTERIZATION_NV);
        }

        // 
        // Execute
        //
        // XXX: make intersector a Task
        HdTaskSharedPtrVector tasks;
        tasks.push_back(boost::make_shared<HdxIntersector_DrawTask>(_renderPass,
                                                               _renderPassState,
                                                            params.renderTags));
        engine->Execute(*_index, tasks);

        glDisable(GL_STENCIL_TEST);

        if (convRstr) {
            // XXX: this should come from Glew
            #define GL_CONSERVATIVE_RASTERIZATION_NV 0x9346
            glDisable(GL_CONSERVATIVE_RASTERIZATION_NV);
        }

        // Restore
        glBindVertexArray(0);
        glDeleteVertexArrays(1, &vao);
    }

    GLF_POST_PENDING_GL_ERRORS();

    //
    // Capture the result buffers to be resolved later.
    //
    size_t len = size[0] * size[1];
    std::unique_ptr<unsigned char[]> primId(new unsigned char[len*4]);
    std::unique_ptr<unsigned char[]> instanceId(new unsigned char[len*4]);
    std::unique_ptr<unsigned char[]> elementId(new unsigned char[len*4]);
    std::unique_ptr<float[]> depths(new float[len]);

    glBindTexture(GL_TEXTURE_2D,
        drawTarget->GetAttachments().at("primId")->GetGlTextureName());
    glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &primId[0]);

    glBindTexture(GL_TEXTURE_2D,
        drawTarget->GetAttachments().at("instanceId")->GetGlTextureName());
    glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &instanceId[0]);

    glBindTexture(GL_TEXTURE_2D,
        drawTarget->GetAttachments().at("elementId")->GetGlTextureName());
    glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &elementId[0]);

    glBindTexture(GL_TEXTURE_2D,
        drawTarget->GetAttachments().at("depth")->GetGlTextureName());
    glGetTexImage(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
                    &depths[0]);

    glBindTexture(GL_TEXTURE_2D, 0);

    GLF_POST_PENDING_GL_ERRORS();

    if (result) {
        *result = HdxIntersector::Result(
            std::move(primId), std::move(instanceId), std::move(elementId),
            std::move(depths), _index, params, viewport);
    }

    drawTarget->Unbind();
    GLF_POST_PENDING_GL_ERRORS();

    return true;
}