本文整理汇总了C++中Composite类的典型用法代码示例。如果您正苦于以下问题:C++ Composite类的具体用法?C++ Composite怎么用?C++ Composite使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Composite类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetPrevChild
Chunk * Composite::GetProperty(ChildNode const * pNode, ID idProp) const
{
// search backward for ID
ChildNode * pFindNode = GetPrevChild(pNode, idProp);
if (pFindNode) return pFindNode->GetChunk();
// if not found, search parent backwards, for "PROP ...." then get that
// and if not in the parent, search its parent similarly
// provided all these parents are of type LIST ....
for (Composite const * pThis = this; pThis->m_pParent && pThis->m_pParent->m_idCk == ID("LIST"); pThis = pThis->m_pParent)
{
if (pThis->m_pNode)
{
for (ChildNode * pFindProp = pThis->m_pParent->GetPrevChild(pThis->m_pNode,"PROP"); pFindProp; pFindProp = pThis->m_pParent->GetPrevChild(pFindProp,"PROP"))
{
Composite * pProp = static_cast<Composite *>(pFindProp->GetChunk());
if (pProp->m_idData == m_idData)
{
ChildNode * pFindNode = pProp->GetLastChild(idProp);
if (pFindNode) return pFindNode->GetChunk();
}
}
}
}
return NULL;
}
示例2: Composite
void LoadExecuter::execute(SceneData &data, Commands c, command_params &p)
{
Model3D *pointer = loader.read_model(p.load_params.file_name);
Composite *composite = new Composite();
composite->add_object(std::shared_ptr<SceneObj>(pointer));
data.add_composite(std::shared_ptr<Composite>(composite), p.load_params.center);
}
示例3: Composite
/** Currently not used. Need to check whether all data should be copied or just pointers.
Current code only copies the pointers **/
Composite * Composite::copy(){
Composite * copy = new Composite();
printf("Composite::copy 1\n");
std::map<CompositeBranchContainer *,CompositeBranchContainer *> new_to_old_map;
std::map<CompositeBranchContainer *,CompositeBranchContainer *> old_to_new_map;
printf("Composite::copy creating new branches\n");
for (CompositeBranchContainer * branch : get_branches()){
CompositeBranchContainer * branch_copy = new CompositeBranchContainer(branch);
new_to_old_map[branch_copy] = branch;
old_to_new_map[branch] = branch_copy;
copy->add_branch(branch_copy);
}
//for (CompositeBranchContainer * new_branch : branches){
// Create parent/child pointers
printf("Composite::copy connecting branches\n");
int count = 0;
for (std::map<CompositeBranchContainer *,CompositeBranchContainer *>::iterator it = new_to_old_map.begin(); it != new_to_old_map.end(); ++it){
CompositeBranchContainer * new_branch = it->first;
CompositeBranchContainer * orig_branch = it->second;
//CompositeBranchContainer * orig_branch = new_to_old_map[new_branch];
CompositeBranchContainer * orig_parent = orig_branch->get_parent();
count++;
//printf("Branch connecting %d; orig_parent %p\n",count,orig_parent);
if (orig_parent){
CompositeBranchContainer * new_parent = old_to_new_map[orig_parent];
// Make child->parent connection
new_branch->set_parent(new_parent);
// Copy parent-side decision points
if (new_parent->get_decision_point2()){
// When the copied decision point already exists
new_branch->set_decision_point1(new_parent->get_decision_point2());
}else{
DecisionPoint * dp_copy = new DecisionPoint(orig_branch->get_decision_point1());
new_branch->set_decision_point1(dp_copy);
decision_points.push_back(dp_copy);
}
}else{
// No parent, so this branch must be the root
printf("setting root\n");
copy->set_root(new_branch);
}
// Copy child-side decision point (if it isn't a certain terminal branch)
if (orig_branch->get_decision_point2()){
//printf("copying dp2 %p\n",orig_branch->get_decision_point2());
DecisionPoint * dp_copy = new DecisionPoint(orig_branch->get_decision_point2());
new_branch->set_decision_point2(dp_copy);
decision_points.push_back(dp_copy);
}
}
printf("Done making copy\n");
return copy;
}
示例4: main
int main()
{
Leaf *mouse = new Leaf(10);
Leaf *mouse2 = new Leaf(20);
Composite *bag = new Composite();
bag->Add(mouse);
bag->Add(mouse2);
cout << bag->GetSize() << endl;
return 0;
}
示例5: CompositeTest
///Composite 组合模式通过和 Decorator 模式有着类似的结构图,但是 Composite 模式旨在构造 类,而 Decorator 模式重在不生成子类即可给对象添加职责。Decorator 模式重在修饰,而 Composite 模式重在表示
void CompositeTest() {
Leaf* l = new Leaf();
l->Operation();
Composite* com = new Composite();
com->Add(l);
com->Operation();
NS_Composite::Component* ll = com->GetChild(0);
ll->Operation();
}
示例6: init
bool PoissonBlendEx::init(Composite& rootNode) {
ImageRGBA srcImg, tarImg;
ReadImageFromFile(getFullPath("images/sfmarket.png"), srcImg);
ReadImageFromFile(getFullPath("images/sfsunset.png"), tarImg);
ConvertImage(srcImg, src);
ConvertImage(tarImg, tar);
ImageGlyphPtr srcGlyph = createImageGlyph(srcImg, false);
ImageGlyphPtr tarGlyph = createImageGlyph(tarImg, false);
ImageGlyphPtr resultGlyph = createImageGlyph(tarImg, false);
GlyphRegionPtr srcRegion = MakeGlyphRegion(srcGlyph,
CoordPercent(0.05f, 0.0f), CoordPercent(0.4f, 0.3f),
AspectRule::FixedWidth, COLOR_NONE, COLOR_NONE,
Color(200, 200, 200, 255), UnitPX(1.0f));
GlyphRegionPtr tarRegion = MakeGlyphRegion(tarGlyph,
CoordPercent(0.55f, 0.0f), CoordPercent(0.4f, 0.3f),
AspectRule::FixedWidth, COLOR_NONE, COLOR_NONE,
Color(200, 200, 200, 255), UnitPX(1.0f));
TextLabelPtr textLabel = TextLabelPtr(
new TextLabel("Solving Poisson Blend ...",
CoordPercent(0.1f, 0.35f), CoordPercent(0.8f, 0.5f)));
textLabel->fontSize = UnitPX(20.0f);
textLabel->fontType = FontType::Bold;
textLabel->fontStyle = FontStyle::Outline;
GlyphRegionPtr resultRegion = MakeGlyphRegion(resultGlyph,
CoordPercent(0.1f, 0.35f), CoordPercent(0.8f, 0.5f),
AspectRule::FixedWidth, COLOR_NONE, COLOR_NONE,
Color(200, 200, 200, 255), UnitPX(1.0f));
rootNode.add(srcRegion);
rootNode.add(tarRegion);
rootNode.add(resultRegion);
rootNode.add(textLabel);
workerTask = WorkerTaskPtr(new Worker([=] {
PoissonBlend(src, tar, 32, 6);
ImageRGBA out;
ConvertImage(tar,out);
getContext()->addDeferredTask([=]() {
resultGlyph->set(out,getContext().get());
textLabel->setLabel("Finished!");
});
}));
workerTask->execute(isForcedClose());
return true;
}
示例7: main
int main()
{
Leaf *pLeaf1 = new Leaf();
Leaf *pLeaf2 = new Leaf();
Composite *pComposite = new Composite;
pComposite->Add(pLeaf1);
pComposite->Add(pLeaf2);
pComposite->Operation();
cout << "pComposite->GetChild(2)->Operation():" << endl;
pComposite->GetChild(2)->Operation();
delete pComposite;
cin.get();
return 0;
}
示例8: update
void AlloyContext::update(Composite& rootNode) {
endTime = std::chrono::steady_clock::now();
double updateElapsed = std::chrono::duration<double>(
endTime - lastUpdateTime).count();
double animateElapsed = std::chrono::duration<double>(
endTime - lastAnimateTime).count();
double cursorElapsed = std::chrono::duration<double>(
endTime - lastCursorTime).count();
if (deferredTasks.size() > 0) {
executeDeferredTasks();
cursorLocator.reset(screenSize);
rootNode.updateCursor(&cursorLocator);
dirtyCursorLocator = false;
mouseOverRegion = locate(cursorPosition);
dirtyCursor = false;
dirtyLayout = true;
}
if (updateElapsed > UPDATE_LOCATOR_INTERVAL_SEC) {
if (dirtyCursorLocator) {
cursorLocator.reset(screenSize);
rootNode.updateCursor(&cursorLocator);
dirtyCursorLocator = false;
mouseOverRegion = locate(cursorPosition);
dirtyCursor = false;
}
lastUpdateTime = endTime;
}
if (cursorElapsed >= UPDATE_CURSOR_INTERVAL_SEC) { //Dont try to animate faster than 60 fps.
if (dirtyCursor && !dirtyCursorLocator) {
mouseOverRegion = locate(cursorPosition);
dirtyCursor = false;
}
dirtyUI = true;
lastCursorTime = endTime;
}
if (animateElapsed >= ANIMATE_INTERVAL_SEC) { //Dont try to animate faster than 60 fps.
lastAnimateTime = endTime;
if (animator.step(animateElapsed)) {
dirtyLayout = true;
dirtyUI = true;
}
}
if (dirtyLayout) {
rootNode.pack(this);
animator.firePostEvents();
dirtyCursorLocator = true;
dirtyLayout = false;
}
}
示例9: lIndentStep
/*!
* \brief TextEditPrintMenuVisitor::indent
* \param item
* \return
*/
QString TextEditPrintMenuVisitor::indent(Composite *item) const
{
QString rIndentString;
QString lIndentStep(" ");
Composite *lMenuItem = item->parent();
while (lMenuItem)
{
lMenuItem = lMenuItem->parent();
rIndentString.append(lIndentStep);
}
return rIndentString;
}
示例10: indent
/*!
* \brief ConsolePrintMenuVisitor::indent
* \param item
* \return
*/
std::string ConsolePrintMenuVisitor::indent(Composite *item) const
{
std::string rIndentString;
std::string lIndentStep = " ";
Composite *lMenuItem = item->parent();
while (lMenuItem)
{
lMenuItem = lMenuItem->parent();
rIndentString.append(lIndentStep);
}
return rIndentString;
}
示例11: main
int main()
{
Leaf * pLeaf1 = new Leaf();
Leaf * pLeaf2 = new Leaf();
Composite * pComposite = new Composite;
pComposite->Add(pLeaf1);
pComposite->Add(pLeaf2);
pComposite->Operation();
pComposite->GetChild(2)->Operation();
delete pComposite;
return 0;
}
示例12: init
bool MeshParticleEx::init(Composite& rootNode) {
box3f renderBBox = box3f(float3(-0.5f, -0.5f, -0.5f),float3(1.0f, 1.0f, 1.0f));
mesh.load(getFullPath("models/monkey.obj"));
mesh.updateVertexNormals();
int N = (int)mesh.vertexLocations.size();
mesh.vertexColors.resize(N);
box3f box = mesh.getBoundingBox();
for (int n = 0; n < N; n++) {
float3 pt = mesh.vertexLocations[n];
pt = (pt - box.position) / box.dimensions;
mesh.vertexColors[n] = HSVAtoRGBAf(HSVA(pt.x, 0.7f, 0.8f, 1.0f));
}
//Make region on screen to render 3d view
renderRegion=MakeRegion("Render View",CoordPerPX(0.5f,0.5f,-256,-256),CoordPX(512,512),COLOR_NONE,COLOR_WHITE,UnitPX(1.0f));
//Initialize depth buffer to store the render
depthFrameBuffer.initialize(512, 512);
//Set up camera
camera.setNearFarPlanes(0.1f, 3.0f);
camera.setZoom(1.0f);
camera.setCameraType(CameraType::Perspective);
camera.setDirty(true);
//Map object geometry into unit bounding box for draw.
camera.setPose(MakeTransform(mesh.getBoundingBox(), renderBBox));
//Add listener to respond to mouse manipulations
addListener(&camera);
//Add render component to root node so it is relatively positioned.
rootNode.add(renderRegion);
return true;
}
示例13: init
bool MeshWireframeEx::init(Composite& rootNode) {
box3f renderBBox = box3f(float3(-0.5f, -0.5f, -0.5f),
float3(1.0f, 1.0f, 1.0f));
mesh.load(getFullPath("models/monkey.obj"));
Subdivide(mesh,SubDivisionScheme::CatmullClark);
mesh.updateVertexNormals();
//Make region on screen to render 3d view
renderRegion = MakeRegion("Render View", CoordPerPX(0.5f, 0.5f, -256, -256),
CoordPX(512, 512), COLOR_NONE, COLOR_WHITE, UnitPX(1.0f));
//Initialize depth buffer to store the render
depthFrameBuffer.initialize(512, 512);
wireframeFrameBuffer.initialize(512, 512);
//Set up camera
camera.setNearFarPlanes(-2.0f, 2.0f);
camera.setZoom(0.75f);
camera.setCameraType(CameraType::Orthographic);
//Map object geometry into unit bounding box for draw.
camera.setPose(MakeTransform(mesh.getBoundingBox(), renderBBox));
//Add listener to respond to mouse manipulations
addListener(&camera);
//Add render component to root node so it is relatively positioned.
rootNode.add(renderRegion);
setOnResize([=](const int2& dims) {
camera.setDirty(true);
});
wireframeShader.setFaceColor(Color(0.1f,0.1f,1.0f,0.5f));
wireframeShader.setEdgeColor(Color(1.0f,0.8f,0.1f,1.0f));
wireframeShader.setLineWidth(1.5f);
return true;
}
示例14: SetTime
void CompositeDlg::SetTime(TimeValue t)
{
Interval valid;
theTex->Update(ip->GetTime(), valid);
LoadDialog(FALSE);
InvalidateRect(hPanel,NULL,0);
}
示例15: getId
void CityObject::finish( AppearanceManager& appearanceManager, const ParserParams& params )
{
Appearance* myappearance = appearanceManager.getAppearance( getId() );
std::vector< Geometry* >::const_iterator itGeom = _geometries.begin();
for ( ; itGeom != _geometries.end(); ++itGeom ) {
if ( !( (*itGeom)->getComposite() ) ) {
(*itGeom)->finish( appearanceManager, myappearance ? myappearance : 0, params );
} else {
Composite* geomComposite = (*itGeom)->getComposite();
myappearance = appearanceManager.getAppearance( geomComposite->getId() );
(*itGeom)->finish( appearanceManager, myappearance ? myappearance : 0, params );
}
}
std::vector< ImplicitGeometry* >::const_iterator itImplGeom = _implicitGeometries.begin();
for( ; itImplGeom != _implicitGeometries.end(); ++itImplGeom) {
for(std::vector< Geometry* >::const_iterator it = (*itImplGeom)->_geometries.begin(); it != (*itImplGeom)->_geometries.end(); ++it) {
if ( !( (*it)->getComposite() ) ) {
(*it)->finish( appearanceManager, myappearance ? myappearance : 0, params );
} else {
Composite* geomComposite = (*it)->getComposite();
myappearance = appearanceManager.getAppearance( geomComposite->getId() );
(*it)->finish( appearanceManager, myappearance ? myappearance : 0, params );
}
}
}
bool finish = false;
while ( !finish && params.optimize )
{
finish = true;
int len = _geometries.size();
for ( int i = 0; finish && i < len - 2; i++ )
{
for ( int j = i+1; finish && j < len - 1; j++ )
{
if ( !_geometries[i]->merge( _geometries[j] ) ) continue;
delete _geometries[j];
_geometries.erase( _geometries.begin() + j );
finish = false;
}
}
}
}