Example #1
0
void PatchGroup::read(Xml& xml)
      {
      for (;;) {
            Xml::Token token = xml.parse();
            const QString& tag = xml.s1();
            switch (token) {
                  case Xml::Error:
                  case Xml::End:
                        return;
                  case Xml::TagStart:
                        if (tag == "Patch") {
                              Patch* patch = new Patch;
                              patch->read(xml);
                              patches.push_back(patch);
                              }
                        else
                              xml.unknown("PatchGroup");
                        break;
                  case Xml::Attribut:
                        if (tag == "name")
                              name = xml.s2();
                        break;
                  case Xml::TagEnd:
                        if (tag == "PatchGroup")
                              return;
                  default:
                        break;
                  }
            }
      }
Example #2
0
int
NPRPen::tap_cb(CGESTUREptr& gest, DrawState*&)
{
   cerr << "NPRPen::tap_cb" << endl;

   Bface *f = VisRefImage::Intersect(gest->center());
   Patch* p = get_ctrl_patch(f);
   if (!(f && p)) {
      if (_curr_npr_tex)
         deselect_current_texture();
      return 0;
   }

   // Set the selected face's patch to using NPRTexture
   // It might already be doing this, but who cares!
   p->set_texture(NPRTexture::static_name());

   GTexture* cur_texture = p->cur_tex();
   NPRTexture* nt = dynamic_cast<NPRTexture*>(cur_texture);
   if (nt == nullptr)
      return 0; //Shouldn't happen

   if (_curr_npr_tex)
      {
         if (_curr_npr_tex != nt)
            {
               deselect_current_texture();
               select_current_texture(nt);
            }
      }
   else
      select_current_texture(nt);

   return 0;
}
Example #3
0
TEST(PatchTest, set_oscillator)
{
  Patch patch;
  SineWaveOscillator osc;
  patch.set_oscillator(&osc);
  ASSERT_TRUE(patch.oscillator() == &osc);
}
void Landscape::Init(float **hMap)
{
    if ( hMap == NULL ) {
        std::cerr<<"Landscape Init NULL pointer"<<std::endl;
    }
    Patch *patch;

    heightMap = new float*[MAP_SIZE+1];
    for ( int i=0;i < MAP_SIZE+1;i++) {
        heightMap[i] = new float[MAP_SIZE+1];
    }
    for ( int i=0; i < MAP_SIZE ; i++) {
        for ( int j = 0;j < MAP_SIZE ;j++) {
            heightMap[i][j] = hMap[i][j];
        }
        heightMap[i][MAP_SIZE] = hMap[i][MAP_SIZE -1 ];
        heightMap[MAP_SIZE][i] = hMap[MAP_SIZE-1][i];
    }

    for ( int Y=0; Y < NUM_PATCHES_PER_SIDE; Y++) {
        for ( int X=0; X < NUM_PATCHES_PER_SIDE; X++ ) {
            patch = &(m_Patches[Y][X]);
            patch->Init(X*(PATCH_SIZE), Y*(PATCH_SIZE), heightMap );
            sorted_distance.push_back(patch);
        }
    }
}
Example #5
0
// given a control patch and (u,v) values, find 
// the surface point and normal
Point Bezier::bezpatchinterp(Patch patch, float u, float v, Point &n) {
	Point p;
	Point dPdu;
	Point dPdv;
	Point trash;
	std::vector<Point> vcurve(4);
	std::vector<Point> ucurve(4);

	bool horizontal = true;
	bool vertical = false;

	// build control points for a Bezier curve in v
	vcurve[0] = bezcurveinterp(patch.getCurve(0, horizontal), u, trash);
	vcurve[1] = bezcurveinterp(patch.getCurve(1, horizontal), u, trash);
	vcurve[2] = bezcurveinterp(patch.getCurve(2, horizontal), u, trash);
	vcurve[3] = bezcurveinterp(patch.getCurve(3, horizontal), u, trash);
	// build control points for a Bezier curve in u
	ucurve[0] = bezcurveinterp(patch.getCurve(0, vertical), v, trash);
	ucurve[1] = bezcurveinterp(patch.getCurve(1, vertical), v, trash);
	ucurve[2] = bezcurveinterp(patch.getCurve(2, vertical), v, trash);
	ucurve[3] = bezcurveinterp(patch.getCurve(3, vertical), v, trash);
	// evaluate surface and derivative for u and v
	p = bezcurveinterp(vcurve, v, dPdv);
	p = bezcurveinterp(ucurve, u, dPdu);
	// take cross product of partials to find normal
	n = crossP(dPdu, dPdv);
	n = n / n.length();
	Point n2 = crossP(dPdv, dPdu);
	n2 = n2 / n2.length();
	p.saveNormal(n, n2);
	return p;
}
Example #6
0
void peanoclaw::interSubgridCommunication::GridLevelTransfer::vetoCoarseningIfNecessary (
  Patch&                               patch,
  peanoclaw::Vertex * const            fineGridVertices,
  const peano::grid::VertexEnumerator& fineGridVerticesEnumerator
) {
  assertion(!patch.isLeaf());

  if(tarch::la::smaller(patch.getTimeIntervals().getTimestepSize(), 0.0)) {
    assertion(!patch.isLeaf());
    bool patchBlocksErasing = false;
    for( int i = 0; i < TWO_POWER_D; i++ ) {
      peanoclaw::Vertex& vertex = fineGridVertices[fineGridVerticesEnumerator(i)];
      if(vertex.shouldErase()) {
        patchBlocksErasing = true;
      }
      vertex.setSubcellEraseVeto(i);
    }

    if(patchBlocksErasing) {
      patch.getTimeIntervals().setFineGridsSynchronize(true);
    }
  } else {
    patch.getTimeIntervals().setFineGridsSynchronize(false);
  }
}
Example #7
0
void PdBase::closePatch(Patch& patch) {
	if(!patch.isValid()) {
		return;
	}
	libpd_closefile(patch.handle());
	patch.clear();
}	
void Landscape::Reset()
{
    Patch *patch;

    SetNextTriNode(0);

    for ( int Y=0; Y < NUM_PATCHES_PER_SIDE; Y++ ) {
        for ( int X=0; X < NUM_PATCHES_PER_SIDE; X++) {
            patch = &(m_Patches[Y][X]);
            patch->Reset();

            if ( X > 0 )
                patch->GetBaseLeft()->LeftNeighbor = m_Patches[Y][X-1].GetBaseRight();
            else
                patch->GetBaseLeft()->LeftNeighbor = NULL;
            if ( X < (NUM_PATCHES_PER_SIDE-1) )
                patch->GetBaseRight()->LeftNeighbor = m_Patches[Y][X+1].GetBaseLeft();
            else
                patch->GetBaseRight()->LeftNeighbor = NULL;

            if ( Y > 0 )
                patch->GetBaseLeft()->RightNeighbor = m_Patches[Y-1][X].GetBaseRight();
            else
                patch->GetBaseLeft()->RightNeighbor = NULL;

            if ( Y < (NUM_PATCHES_PER_SIDE-1) )
                patch->GetBaseRight()->RightNeighbor = m_Patches[Y+1][X].GetBaseLeft();
            else
                patch->GetBaseRight()->RightNeighbor = NULL;
        }
    }
}
Example #9
0
//Patch::Patch(const Eigen::Vector3d& p,const Eigen::Vector3d& n,const unsigned int& nIm,
//      const Eigen::Vector3i& inds)
//  : point_(p),normal_(n),nImgs_(nIm),inds_(inds)
//  {}
Patch::Patch(const Patch& p)
  : point_(p.getPoint()),
    pointInd_(p.getPointInd()),
    normal_(p.getNormal()),
    nImgs_(p.getNImages()),
    inds_(p.getInds())
  {}
Example #10
0
void LMarkerCoarsen::coarsen(Patch<NDIM>& coarse,
                             const Patch<NDIM>& fine,
                             const int dst_component,
                             const int src_component,
                             const Box<NDIM>& coarse_box,
                             const IntVector<NDIM>& ratio) const
{
    Pointer<LMarkerSetData> dst_mark_data = coarse.getPatchData(dst_component);
    Pointer<LMarkerSetData> src_mark_data = fine.getPatchData(src_component);

    const Box<NDIM> fine_box = Box<NDIM>::refine(coarse_box, ratio);
    for (LMarkerSetData::SetIterator it(*src_mark_data); it; it++)
    {
        const Index<NDIM>& fine_i = it.getIndex();
        const Index<NDIM> coarse_i = coarsen_index(fine_i, ratio);
        if (fine_box.contains(fine_i) && coarse_box.contains(coarse_i))
        {
            const LMarkerSet& fine_mark_set = it();
            if (!dst_mark_data->isElement(coarse_i))
            {
                dst_mark_data->appendItemPointer(coarse_i, new LMarkerSet());
            }
            LMarkerSet& coarse_mark_set = *(dst_mark_data->getItem(coarse_i));
            coarse_mark_set.insert(
                coarse_mark_set.end(), fine_mark_set.begin(), fine_mark_set.end());
        }
    }
    return;
} // coarsen
Example #11
0
Transform* PatchSet::createPatch(const std::string& filename, PatchOptions* poptions)
{
    Patch* patch = new Patch;
    patch->setPatchSet(this);
    Vec2d ll, ur;
    poptions->getPatchExtents(ll, ur);
    Vec2d range = (ur - ll);
    ref_ptr<Patch::Data> data = new Patch::Data;
    int patchDim = _resolution + 1;
    Vec3Array* verts = new Vec3Array(patchDim * patchDim);
    for (int j = 0; j < patchDim; ++j)
        for (int i = 0; i < patchDim; ++i)
            (*verts)[patchDim * j + i]
                = Vec3((ll.x() + i * range.x()
                        / static_cast<float>(_resolution)) * 81920.0,
                       (ll.y() + j * range.y()
                        / static_cast<float>(_resolution)) * 81920.0,
                       0.0);
    data->vertexData.array = verts;
    data->vertexData.binding = Geometry::BIND_PER_VERTEX;
    Vec3Array* norms = new Vec3Array(1);
    (*norms)[0] = Vec3d(0.0, 0.0, 1.0);
    data->normalData.array = norms;
    data->normalData.binding = Geometry::BIND_OVERALL;
    Vec4Array* colors = new Vec4Array(1);
    (*colors)[0] = Vec4(1.0, 1.0, 1.0, 1.0);
    data->colorData.array = colors;
    data->colorData.binding = Geometry::BIND_OVERALL;
    patch->setData(data);
    MatrixTransform* transform = new MatrixTransform;
    transform->addChild(patch);
    return transform;
}
Example #12
0
const Patch* PatchCache::get(const AssetAtlas::Entry* entry,
        const uint32_t bitmapWidth, const uint32_t bitmapHeight,
        const float pixelWidth, const float pixelHeight, const Res_png_9patch* patch) {

    const PatchDescription description(bitmapWidth, bitmapHeight, pixelWidth, pixelHeight, patch);
    const Patch* mesh = mCache.get(description);

    if (!mesh) {
        Patch* newMesh = new Patch();
        TextureVertex* vertices;

        if (entry) {
            // An atlas entry has a UV mapper
            vertices = newMesh->createMesh(bitmapWidth, bitmapHeight,
                    pixelWidth, pixelHeight, entry->uvMapper, patch);
        } else {
            vertices = newMesh->createMesh(bitmapWidth, bitmapHeight,
                    pixelWidth, pixelHeight, patch);
        }

        if (vertices) {
            setupMesh(newMesh, vertices);
        }

#if DEBUG_PATCHES
        if (g_HWUI_debug_patches) dumpFreeBlocks("Adding patch");
#endif

        mCache.put(description, newMesh);
        return newMesh;
    }

    return mesh;
}
void CartCellRobinPhysBdryOp::fillGhostCellValuesCodim2(
    const int patch_data_idx,
    const Array<BoundaryBox<NDIM> >& physical_codim2_boxes,
    const IntVector<NDIM>& ghost_width_to_fill,
    const Patch<NDIM>& patch,
    const bool adjoint_op)
{
    const int n_physical_codim2_boxes = physical_codim2_boxes.size();
    if (n_physical_codim2_boxes == 0) return;

    const Box<NDIM>& patch_box = patch.getBox();
    Pointer<CartesianPatchGeometry<NDIM> > pgeom = patch.getPatchGeometry();
    Pointer<CellData<NDIM, double> > patch_data = patch.getPatchData(patch_data_idx);
    const int patch_data_depth = patch_data->getDepth();
    const int patch_data_gcw = (patch_data->getGhostCellWidth()).max();
#if !defined(NDEBUG)
    if (patch_data_gcw != (patch_data->getGhostCellWidth()).min())
    {
        TBOX_ERROR(
            "CartCellRobinPhysBdryOp::fillGhostCellValuesCodim2():\n"
            "  patch data for patch data index "
            << patch_data_idx << " does not have uniform ghost cell widths." << std::endl);
    }
#endif
    const IntVector<NDIM> gcw_to_fill =
        IntVector<NDIM>::min(patch_data->getGhostCellWidth(), ghost_width_to_fill);

    for (int n = 0; n < n_physical_codim2_boxes; ++n)
    {
        const BoundaryBox<NDIM>& bdry_box = physical_codim2_boxes[n];
        const unsigned int location_index = bdry_box.getLocationIndex();
        const Box<NDIM> bc_fill_box =
            pgeom->getBoundaryFillBox(bdry_box, patch_box, gcw_to_fill);
        for (int d = 0; d < patch_data_depth; ++d)
        {
            CC_ROBIN_PHYS_BDRY_OP_2_FC(patch_data->getPointer(d),
                                       patch_data_gcw,
                                       location_index,
                                       patch_box.lower(0),
                                       patch_box.upper(0),
                                       patch_box.lower(1),
                                       patch_box.upper(1),
#if (NDIM == 3)
                                       patch_box.lower(2),
                                       patch_box.upper(2),
#endif
                                       bc_fill_box.lower(0),
                                       bc_fill_box.upper(0),
                                       bc_fill_box.lower(1),
                                       bc_fill_box.upper(1),
#if (NDIM == 3)
                                       bc_fill_box.lower(2),
                                       bc_fill_box.upper(2),
#endif
                                       adjoint_op ? 1 : 0);
        }
    }
    return;
} // fillGhostCellValuesCodim2
Example #14
0
SKY_BOX::SKY_BOX()
{
   set_name("Skybox"); 

   // for debugging
//   set_color(Color::blue);

   // build the skybox mesh:
   LMESHptr sky_mesh = make_shared<LMESH>();
   Patch* p = nullptr;
   //sky_mesh->Sphere();

   sky_mesh->UV_BOX(p);

   p->set_sps_regularity(8.0);
   p-> set_do_lod(false);

    //sky_mesh->Cube();
   //sky_mesh->Icosahedron();


  //sky_mesh->read_file(**(Config::JOT_ROOT()+"/../models/simple/sphere.sm"));
   //sky_mesh->read_file(**(Config::JOT_ROOT()+"/../models/simple/sphere-no-uvs.sm"));
   //sky_mesh->read_file(**(Config::JOT_ROOT()+"/../models/simple/icosahedron.sm"));
  // sky_mesh->update_subdivision(3);

 

   //flip normals
   const double RADIUS =1000;

   Wvec d = Wpt::Origin()-sky_mesh->get_bb().center();
   sky_mesh->transform(Wtransf::scaling(RADIUS)*
                       Wtransf::translation(d),MOD());
   //sky_mesh->reverse();
 

   // TODO : make it use skybox texture for the reference image
   //        and proxy surface for the main draw
   
   //Skybox renders in default style now
   //skybox texture only draws the gradient
   //Translation bug fixed for the 10th time he he

   //the skybox GEOM contains a bode with the sphere geometry
   set_body(sky_mesh); 

   //world creation 
   if (_sky_instance)
      err_msg("SKY_BOX::SKY_BOX: warning: instance exists");
   _sky_instance = this;
   
   atexit(SKY_BOX::clean_on_exit);

   WORLD::create(_sky_instance, false);
   WORLD::undisplay(_sky_instance, false);//otherwise it starts up visible
   if (Config::get_var_bool("SHOW_SKYBOX",false))
      show();
}
Example #15
0
 void IRGenerator::applyPatches(char* pcode)
 {
    for ( std::size_t index = 0; index < mPatches.size(); ++index )
    {
       Patch* ppatch = mPatches[index];
       ppatch->apply(pcode);
    }
 }
Example #16
0
Assembly *GraspGLObjects::CreateStarrySky( void ) {
	Assembly *sky = new Assembly();
	Patch *patch = new Patch( room_radius * 4.4, room_radius * 4.4 );
	patch->SetTexture( sky_texture );
	sky->AddComponent( patch );
	sky->SetColor(WHITE);
	return( sky );
}
Example #17
0
Assembly *GraspGLObjects::CreateDarkSky( void ) {
	Assembly *darkSky = new Assembly();
	Patch *patch = new Patch( room_radius * 2.2, room_radius * 2.2 );
	patch->SetTexture( sky_texture );// there is something strange if I dont put the texture the ligthing of the whole tunnel changes
	darkSky->AddComponent( patch );
	darkSky->SetColor( BLACK );
	darkSky->enabled = false;
	return( darkSky );
}
Example #18
0
int LuaPatch::attribute(lua_State* L)
{
    Patch *p = checkInstance(L, 1);
    const char *attr = luaL_checklstring(L, 2, 0);

    lua_pushstring(L, p->attribute(attr).c_str());

    return 1;
}
Example #19
0
void ofxPd::closePatch(Patch& patch) {
	
	ofLog(OF_LOG_VERBOSE, "ofxPd: Closing patch: %s", patch.filename().c_str());
	
	_LOCK();
	libpd_closefile(patch.handle());
	_UNLOCK();
	patch.clear();
}	
Example #20
0
int LuaPatch::setAttribute(lua_State* L)
{
    Patch *p = checkInstance(L, 1);
    const char *attr = luaL_checklstring(L, 2, 0);
    const char *value = luaL_checklstring(L, 3, 0);

    p->setAttribute(attr, value);

    return 0;
}
void
AutoSeg::saveStat (Patch &p)
{
  total_cos_angles_.push_back (p.getCng ());

  Vector2d sk;
  sk = p.getSK();
  total_kx_.push_back (sk(0));
  total_ky_.push_back (sk(1));
}
Example #22
0
void LMarkerRefine::refine(Patch<NDIM>& fine,
                           const Patch<NDIM>& coarse,
                           const int dst_component,
                           const int src_component,
                           const Box<NDIM>& fine_box,
                           const IntVector<NDIM>& ratio) const
{
    Pointer<LMarkerSetData> dst_mark_data = fine.getPatchData(dst_component);
    Pointer<LMarkerSetData> src_mark_data = coarse.getPatchData(src_component);

    const Box<NDIM>& fine_patch_box = fine.getBox();
    const Pointer<CartesianPatchGeometry<NDIM> > fine_patch_geom = fine.getPatchGeometry();
    const Index<NDIM>& fine_patch_lower = fine_patch_box.lower();
    const Index<NDIM>& fine_patch_upper = fine_patch_box.upper();
    const double* const fine_patchXLower = fine_patch_geom->getXLower();
    const double* const fine_patchXUpper = fine_patch_geom->getXUpper();
    const double* const fine_patchDx = fine_patch_geom->getDx();

    const Pointer<CartesianPatchGeometry<NDIM> > coarse_patch_geom = coarse.getPatchGeometry();
    const double* const coarse_patchDx = coarse_patch_geom->getDx();

    const Box<NDIM> coarse_box = Box<NDIM>::coarsen(fine_box, ratio);
    for (LMarkerSetData::SetIterator it(*src_mark_data); it; it++)
    {
        const Index<NDIM>& coarse_i = it.getIndex();
        if (coarse_box.contains(coarse_i))
        {
            const LMarkerSet& coarse_mark_set = it();
            for (LMarkerSet::const_iterator cit = coarse_mark_set.begin(); cit != coarse_mark_set.end(); ++cit)
            {
                const LMarkerSet::value_type& coarse_mark = *cit;
                const Point& X = coarse_mark->getPosition();
                const IntVector<NDIM>& offset = coarse_mark->getPeriodicOffset();
                boost::array<double, NDIM> X_shifted;
                for (unsigned int d = 0; d < NDIM; ++d)
                {
                    X_shifted[d] = X[d] + static_cast<double>(offset(d)) * coarse_patchDx[d];
                }

                const Index<NDIM> fine_i = IndexUtilities::getCellIndex(
                    X_shifted, fine_patchXLower, fine_patchXUpper, fine_patchDx, fine_patch_lower, fine_patch_upper);
                if (fine_box.contains(fine_i))
                {
                    if (!dst_mark_data->isElement(fine_i))
                    {
                        dst_mark_data->appendItemPointer(fine_i, new LMarkerSet());
                    }
                    LMarkerSet& fine_mark_set = *(dst_mark_data->getItem(fine_i));
                    fine_mark_set.push_back(coarse_mark);
                }
            }
        }
    }
    return;
} // refine
  void CRasterTerrainModel::Render() const 
  {
    //glColor3f(1.0f, 0.0f, 0.0f);
    if (glPrimitiveRestartIndex == nullptr)  {
      GLenum glew_err = glewInit();
      if (glew_err != GLEW_NO_ERROR) {
        std::cout << "failed to initialize opengl extension wrapper: " << (const char*)glewGetErrorString(glew_err) << std::endl;
        return;
      }
    }
    
    glEnable(GL_POLYGON_OFFSET_FILL);
    glEnable(GL_POLYGON_OFFSET_LINE);
    glPolygonOffset(1.0, 1.0);
    

    glEnable(GL_PRIMITIVE_RESTART);
    glPrimitiveRestartIndex(UINT_MAX);
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);

    //reset number of rendered triangles
    mNumberOfRenderedTriangles = 0;

    std::vector<Patch*>::const_iterator itr, itre = mActivePatches.end();
    for (itr = mActivePatches.begin(); itr != itre; ++itr) {
      Patch* p = (*itr);

      //compute id
      uint hlv = p->neigbor[0] ? p->neigbor[0]->tessLevel : 0;
      uint vlv = p->neigbor[1] ? p->neigbor[1]->tessLevel : 0;
      uint cid = p->GetCIndex();
      uint tessID = vlv + hlv*mTessLevels + cid*(mTessLevels*mTessLevels);

      glBindBuffer(GL_ARRAY_BUFFER, p->glbuf);
      glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mTessellationIBOs[tessID]);
      glVertexPointer(3, GL_FLOAT, sizeof(CRasterTerrainModel::Vertex), 0);
      glNormalPointer(GL_FLOAT, sizeof(CRasterTerrainModel::Vertex), (void*)12);
      //glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>((*itr)->vbuf.size()));
      glDrawElements(GL_TRIANGLE_STRIP, static_cast<GLsizei>(mTessellationIBufs[tessID].size()), GL_UNSIGNED_INT, 0);

      //count number of rendered triangles
      mNumberOfRenderedTriangles += static_cast<unsigned int>(mTessellationIBufs[tessID].size());
    }

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glDisableClientState(GL_NORMAL_ARRAY);
    glDisable(GL_PRIMITIVE_RESTART);
    glDisable(GL_POLYGON_OFFSET_LINE);
    glDisable(GL_POLYGON_OFFSET_FILL);
  }
Example #24
0
pd::Patch ofxPd::openPatch(pd::Patch& patch) {
	
	ofLogVerbose("Pd") << "opening patch: "+patch.filename()+" path: "+patch.path();
	
	_LOCK();
	Patch p = PdBase::openPatch(patch);
	_UNLOCK();
	if(!p.isValid()) {
		ofLogError("Pd") << "opening patch \""+patch.filename()+"\" failed";
	}
	
	return p;
}
Example #25
0
int LuaPatch::addPoints(lua_State* L)
{
    // ok, we gonna receive as many points as passed to the method
    int nr_args = lua_gettop(L);
    Patch *p = checkInstance(L, 1);

    for(int i = 2; i <= nr_args; i++) {
        Point *pt = LuaPoint::checkInstance(L, i);
        p->addPoint(*pt);
    }

    return 0;
}
Example #26
0
void
write_normals(const BMESH &mesh, ostream &os)
{
   Formatter out(&os, 77);
   out.write("          normal     [");
   IVNormalIterator iter(&out);
   for (int p = 0; p < mesh.patches().num(); p++) {
      Patch *patch = mesh.patches()[p];
      patch->draw_tri_strips(&iter);
   }
   os << "]" << endl;
   os << "            normalBinding  PER_FACE" << endl;
}
Example #27
0
Patch * TerrainPager::findPatch(const PatchID &patchID)
{
	// TODO: find a better method than sequential search.
	Patch *pPatch;
	PATCH_LIST_ITERATOR t, e = workingSet.end();
	for (t = workingSet.begin(); t != e; ++t)
	{
		pPatch = *t;
		if (pPatch->GetID() == patchID)
			return pPatch;
	}

	return NULL;
}
Example #28
0
RectTorus::RectTorus(Geometry *g, qreal iRad, qreal oRad, qreal depth, int k)
{
    QVector<QVector3D> inside;
    QVector<QVector3D> outside;
    for (int i = 0; i < k; ++i) {
        qreal angle = (i * 2 * M_PI) / k;
        inside << QVector3D(iRad * qSin(angle), iRad * qCos(angle), depth / 2.0);
        outside << QVector3D(oRad * qSin(angle), oRad * qCos(angle), depth / 2.0);
    }
    inside << QVector3D(0.0, iRad, 0.0);
    outside << QVector3D(0.0, oRad, 0.0);
    QVector<QVector3D> in_back = extrude(inside, depth);
    QVector<QVector3D> out_back = extrude(outside, depth);

    // Create front, back and sides as separate patches so that smooth normals
    // are generated for the curving sides, but a faceted edge is created between
    // sides and front/back
    Patch *front = new Patch(g);
    for (int i = 0; i < k; ++i)
        front->addQuad(outside[i], inside[i],
                       inside[(i + 1) % k], outside[(i + 1) % k]);
    Patch *back = new Patch(g);
    for (int i = 0; i < k; ++i)
        back->addQuad(in_back[i], out_back[i],
                      out_back[(i + 1) % k], in_back[(i + 1) % k]);
    Patch *is = new Patch(g);
    for (int i = 0; i < k; ++i)
        is->addQuad(in_back[i], in_back[(i + 1) % k],
                    inside[(i + 1) % k], inside[i]);
    Patch *os = new Patch(g);
    for (int i = 0; i < k; ++i)
        os->addQuad(out_back[(i + 1) % k], out_back[i],
                    outside[i], outside[(i + 1) % k]);
    parts << front << back << is << os;
}
Example #29
0
RectPrism::RectPrism(Geometry *g, qreal width, qreal height, qreal depth)
{
    enum { bl, br, tr, tl };
    Patch *fb = new Patch(g);
    fb->setSmoothing(Patch::Faceted);

    // front face
    QVector<QVector3D> r(4);
    r[br].setX(width);
    r[tr].setX(width);
    r[tr].setY(height);
    r[tl].setY(height);
    QVector3D adjToCenter(-width / 2.0, -height / 2.0, depth / 2.0);
    for (int i = 0; i < 4; ++i)
        r[i] += adjToCenter;
    fb->addQuad(r[bl], r[br], r[tr], r[tl]);

    // back face
    QVector<QVector3D> s = extrude(r, depth);
    fb->addQuad(s[tl], s[tr], s[br], s[bl]);

    // side faces
    Patch *sides = new Patch(g);
    sides->setSmoothing(Patch::Faceted);
    sides->addQuad(s[bl], s[br], r[br], r[bl]);
    sides->addQuad(s[br], s[tr], r[tr], r[br]);
    sides->addQuad(s[tr], s[tl], r[tl], r[tr]);
    sides->addQuad(s[tl], s[bl], r[bl], r[tl]);

    parts << fb << sides;
}
Example #30
0
    void onDrawContent(SkCanvas* canvas) override {
        const int nu = 10;
        const int nv = 10;

        SkPaint paint;
        paint.setDither(true);
        paint.setFilterQuality(kLow_SkFilterQuality);

        canvas->translate(DX, DY);

        Patch   patch;

        paint.setShader(fShader0);
        if (fSize0.fX == 0) {
            fSize0.fX = 1;
        }
        if (fSize0.fY == 0) {
            fSize0.fY = 1;
        }
        patch.setBounds(fSize0.fX, fSize0.fY);

        patch.setPatch(fPts);
        drawpatches(canvas, paint, nu, nv, &patch);

        paint.setShader(nullptr);
        paint.setAntiAlias(true);
        paint.setStrokeWidth(SkIntToScalar(5));
        canvas->drawPoints(SkCanvas::kPoints_PointMode, SK_ARRAY_COUNT(fPts), fPts, paint);

        canvas->translate(0, SkIntToScalar(300));

        paint.setAntiAlias(false);
        paint.setShader(fShader1);
        if (true) {
            SkMatrix m;
            m.setSkew(1, 0);
            SkShader* s = SkShader::CreateLocalMatrixShader(paint.getShader(), m);
            paint.setShader(s)->unref();
        }
        if (true) {
            SkMatrix m;
            m.setRotate(fAngle);
            SkShader* s = SkShader::CreateLocalMatrixShader(paint.getShader(), m);
            paint.setShader(s)->unref();
        }
        patch.setBounds(fSize1.fX, fSize1.fY);
        drawpatches(canvas, paint, nu, nv, &patch);
    }