Example #1
0
void Controller::CloseFile()
{
	WShape::setCurrentId(0);
	_ListOfModels.clear();

	// We deallocate the memory:
	ClearRootNode();
	DeleteWingedEdge();
	DeleteViewMap();

	// clears the canvas
	_Canvas->Clear();

	// soc: reset passes
	setPassDiffuse(NULL, 0, 0);
	setPassZ(NULL, 0, 0);
}
Example #2
0
void Controller::ComputeViewMap()
{
	if (!_ListOfModels.size())
		return;

	DeleteViewMap(true);

	// retrieve the 3D viewpoint and transformations information
	//----------------------------------------------------------
	// Save the viewpoint context at the view level in order 
	// to be able to restore it later:

	// Restore the context of view:
	// we need to perform all these operations while the 
	// 3D context is on.
	Vec3f vp(UNPACK3(g_freestyle.viewpoint));

#if 0
	if (G.debug & G_DEBUG_FREESTYLE) {
		cout << "mv" << endl;
	}
#endif
	real mv[4][4];
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++) {
			mv[i][j] = g_freestyle.mv[i][j];
#if 0
			if (G.debug & G_DEBUG_FREESTYLE) {
				cout << mv[i][j] << " ";
			}
#endif
		}
#if 0
		if (G.debug & G_DEBUG_FREESTYLE) {
			cout << endl;
		}
#endif
	}

#if 0
	if (G.debug & G_DEBUG_FREESTYLE) {
		cout << "\nproj" << endl;
	}
#endif
	real proj[4][4];
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++) {
			proj[i][j] = g_freestyle.proj[i][j];
#if 0
			if (G.debug & G_DEBUG_FREESTYLE) {
				cout << proj[i][j] << " ";
			}
#endif
		}
#if 0
		if (G.debug & G_DEBUG_FREESTYLE) {
			cout << endl;
		}
#endif
	}

	int viewport[4];
	for (int i = 0; i < 4; i++)
		viewport[i] = g_freestyle.viewport[i];

#if 0
	if (G.debug & G_DEBUG_FREESTYLE) {
		cout << "\nfocal:" << _pView->GetFocalLength() << endl << endl;
	}
#endif

	// Flag the WXEdge structure for silhouette edge detection:
	//----------------------------------------------------------

	if (G.debug & G_DEBUG_FREESTYLE) {
		cout << "\n===  Detecting silhouette edges  ===" << endl;
	}
	_Chrono.start();

	edgeDetector.setViewpoint(vp);
	edgeDetector.enableOrthographicProjection(proj[3][3] != 0.0);
	edgeDetector.enableRidgesAndValleysFlag(_ComputeRidges);
	edgeDetector.enableSuggestiveContours(_ComputeSuggestive);
	edgeDetector.enableMaterialBoundaries(_ComputeMaterialBoundaries);
	edgeDetector.enableFaceSmoothness(_EnableFaceSmoothness);
	edgeDetector.setCreaseAngle(_creaseAngle);
	edgeDetector.setSphereRadius(_sphereRadius);
	edgeDetector.setSuggestiveContourKrDerivativeEpsilon(_suggestiveContourKrDerivativeEpsilon);
	edgeDetector.setRenderMonitor(_pRenderMonitor);
	edgeDetector.processShapes(*_winged_edge);

	real duration = _Chrono.stop();
	if (G.debug & G_DEBUG_FREESTYLE) {
		printf("Feature lines    : %lf\n", duration);
	}

	if (_pRenderMonitor->testBreak())
		return;

	// Builds the view map structure from the flagged WSEdge structure:
	//----------------------------------------------------------
	ViewMapBuilder vmBuilder;
	vmBuilder.setEnableQI(_EnableQI);
	vmBuilder.setViewpoint(vp);
	vmBuilder.setTransform(mv, proj, viewport, _pView->GetFocalLength(), _pView->GetAspect(), _pView->GetFovyRadian());
	vmBuilder.setFrustum(_pView->znear(), _pView->zfar());
	vmBuilder.setGrid(&_Grid);
	vmBuilder.setRenderMonitor(_pRenderMonitor);

#if 0
	// Builds a tesselated form of the silhouette for display purpose:
	//---------------------------------------------------------------
	ViewMapTesselator3D sTesselator3d;
	ViewMapTesselator2D sTesselator2d;
	sTesselator2d.setNature(_edgeTesselationNature);
	sTesselator3d.setNature(_edgeTesselationNature);
#endif

	if (G.debug & G_DEBUG_FREESTYLE) {
		cout << "\n===  Building the view map  ===" << endl;
	}
	_Chrono.start();
	// Build View Map
	_ViewMap = vmBuilder.BuildViewMap(*_winged_edge, _VisibilityAlgo, _EPSILON, _Scene3dBBox, _SceneNumFaces);
	_ViewMap->setScene3dBBox(_Scene3dBBox);

	if (G.debug & G_DEBUG_FREESTYLE) {
		printf("ViewMap edge count : %i\n", _ViewMap->viewedges_size());
	}

#if 0
	// Tesselate the 3D edges:
	_SilhouetteNode = sTesselator3d.Tesselate(_ViewMap);
	_SilhouetteNode->addRef();

	// Tesselate 2D edges
	_ProjectedSilhouette = sTesselator2d.Tesselate(_ViewMap);
	_ProjectedSilhouette->addRef();
#endif

	duration = _Chrono.stop();
	if (G.debug & G_DEBUG_FREESTYLE) {
		printf("ViewMap building : %lf\n", duration);
	}

#if 0
	_pView->AddSilhouette(_SilhouetteNode);
	_pView->AddSilhouette(_WRoot);
	_pView->Add2DSilhouette(_ProjectedSilhouette);
	_pView->Add2DVisibleSilhouette(_VisibleProjectedSilhouette);
	_pView->AddDebug(_DebugNode);
#endif

	// Draw the steerable density map:
	//--------------------------------
	if (_ComputeSteerableViewMap) {
		ComputeSteerableViewMap();
	}
	// Reset Style modules modification flags
	resetModified(true);

	DeleteWingedEdge();
}
Example #3
0
int Controller::LoadMesh(Render *re, SceneRenderLayer *srl)
{
	BlenderFileLoader loader(re, srl);

	loader.setRenderMonitor(_pRenderMonitor);

	_Chrono.start();

	NodeGroup *blenderScene = loader.Load();

	if (blenderScene == NULL) {
		if (G.debug & G_DEBUG_FREESTYLE) {
			cout << "Cannot load scene" << endl;
		}
		return 1;
	}

	if (blenderScene->numberOfChildren() < 1) {
		if (G.debug & G_DEBUG_FREESTYLE) {
			cout << "Empty scene" << endl;
		}
		blenderScene->destroy();
		delete blenderScene;
		return 1;
	}

	real duration = _Chrono.stop();
	if (G.debug & G_DEBUG_FREESTYLE) {
		cout << "Scene loaded" << endl;
		printf("Mesh cleaning    : %lf\n", duration);
		printf("View map cache   : %s\n", _EnableViewMapCache ? "enabled" : "disabled");
	}
	_SceneNumFaces += loader.numFacesRead();

#if 0
	if (loader.minEdgeSize() < _minEdgeSize) {
		_minEdgeSize = loader.minEdgeSize();
	}
#endif

#if 0  // DEBUG
	ScenePrettyPrinter spp;
	blenderScene->accept(spp);
#endif

	_RootNode->AddChild(blenderScene);
	_RootNode->UpdateBBox(); // FIXME: Correct that by making a Renderer to compute the bbox

	_pView->setModel(_RootNode);
	//_pView->FitBBox();

	if (_pRenderMonitor->testBreak())
		return 0;

	if (_EnableViewMapCache) {

		NodeCamera *cam;
		if (g_freestyle.proj[3][3] != 0.0)
			cam = new NodeOrthographicCamera;
		else
			cam = new NodePerspectiveCamera;
		double proj[16];
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 4; j++) {
				proj[i * 4 + j] = g_freestyle.proj[i][j];
			}
		}
		cam->setProjectionMatrix(proj);
		_RootNode->AddChild(cam);
		_RootNode->AddChild(new NodeSceneRenderLayer(*re->scene, *srl));

		sceneHashFunc.reset();
		//blenderScene->accept(sceneHashFunc);
		_RootNode->accept(sceneHashFunc);
		if (G.debug & G_DEBUG_FREESTYLE) {
			cout << "Scene hash       : " << sceneHashFunc.toString() << endl;
		}
		if (hitViewMapCache()) {
			ClearRootNode();
			return 0;
		}
		else {
			delete _ViewMap;
			_ViewMap = NULL;
		}
	}

	_Chrono.start();

	WXEdgeBuilder wx_builder;
	wx_builder.setRenderMonitor(_pRenderMonitor);
	blenderScene->accept(wx_builder);
	_winged_edge = wx_builder.getWingedEdge();

	duration = _Chrono.stop();
	if (G.debug & G_DEBUG_FREESTYLE) {
		printf("WEdge building   : %lf\n", duration);
	}

#if 0
	_pView->setDebug(_DebugNode);

	// delete stuff
	if (0 != ws_builder) {
		delete ws_builder;
		ws_builder = 0;
	}

	soc QFileInfo qfi(iFileName);
	soc string basename((const char*)qfi.fileName().toAscii().data());
	char cleaned[FILE_MAX];
	BLI_strncpy(cleaned, iFileName, FILE_MAX);
	BLI_cleanup_file(NULL, cleaned);
	string basename = string(cleaned);
#endif

	_ListOfModels.push_back("Blender_models");

	_Scene3dBBox = _RootNode->bbox();

	_bboxDiag = (_RootNode->bbox().getMax() - _RootNode->bbox().getMin()).norm();
	if (G.debug & G_DEBUG_FREESTYLE) {
		cout << "Triangles nb     : " << _SceneNumFaces << " imported, " <<
		        _winged_edge->getNumFaces() << " retained" << endl;
		cout << "Bounding Box     : " << _bboxDiag << endl;
	}

	ClearRootNode();

	_SceneNumFaces = _winged_edge->getNumFaces();
	if (_SceneNumFaces == 0) {
		DeleteWingedEdge();
		return 1;
	}

	return 0;
}
Example #4
0
int Controller::LoadMesh(Render *re, SceneRenderLayer *srl)
{
    BlenderFileLoader loader(re, srl);

    loader.setRenderMonitor(_pRenderMonitor);

    _Chrono.start();

    NodeGroup *blenderScene = loader.Load();

    if (blenderScene == NULL) {
        if (G.debug & G_DEBUG_FREESTYLE) {
            cout << "Cannot load scene" << endl;
        }
        return 1;
    }

    if (blenderScene->numberOfChildren() < 1) {
        if (G.debug & G_DEBUG_FREESTYLE) {
            cout << "Empty scene" << endl;
        }
        blenderScene->destroy();
        delete blenderScene;
        return 1;
    }

    real duration = _Chrono.stop();
    if (G.debug & G_DEBUG_FREESTYLE) {
        cout << "Scene loaded" << endl;
        printf("Mesh cleaning    : %lf\n", duration);
    }
    _SceneNumFaces += loader.numFacesRead();

    if (loader.minEdgeSize() < _minEdgeSize) {
        _minEdgeSize = loader.minEdgeSize();
    }

#if 0  // DEBUG
    ScenePrettyPrinter spp;
    blenderScene->accept(spp);
#endif

    _RootNode->AddChild(blenderScene);
    _RootNode->UpdateBBox(); // FIXME: Correct that by making a Renderer to compute the bbox

    _pView->setModel(_RootNode);
    //_pView->FitBBox();

    if (_pRenderMonitor->testBreak())
        return 0;

    _Chrono.start();

    WXEdgeBuilder wx_builder;
    wx_builder.setRenderMonitor(_pRenderMonitor);
    blenderScene->accept(wx_builder);
    _winged_edge = wx_builder.getWingedEdge();

    duration = _Chrono.stop();
    if (G.debug & G_DEBUG_FREESTYLE) {
        printf("WEdge building   : %lf\n", duration);
    }

#if 0
    _pView->setDebug(_DebugNode);

    // delete stuff
    if (0 != ws_builder) {
        delete ws_builder;
        ws_builder = 0;
    }

    soc QFileInfo qfi(iFileName);
    soc string basename((const char*)qfi.fileName().toAscii().data());
    char cleaned[FILE_MAX];
    BLI_strncpy(cleaned, iFileName, FILE_MAX);
    BLI_cleanup_file(NULL, cleaned);
    string basename = string(cleaned);
#endif

    _ListOfModels.push_back("Blender_models");

    _Scene3dBBox = _RootNode->bbox();

    _bboxDiag = (_RootNode->bbox().getMax() - _RootNode->bbox().getMin()).norm();
    if (G.debug & G_DEBUG_FREESTYLE) {
        cout << "Triangles nb     : " << _SceneNumFaces << " imported, " <<
             _winged_edge->getNumFaces() << " retained" << endl;
        cout << "Bounding Box     : " << _bboxDiag << endl;
    }

    ClearRootNode();

    _SceneNumFaces = _winged_edge->getNumFaces();
    if (_SceneNumFaces == 0) {
        DeleteWingedEdge();
        return 1;
    }

    return 0;
}