Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

https://github.com/lwt831/Real-time-Locally-Injective-Volumetric-Deformation
29 January 2026, 01:41:28 UTC
  • Code
  • Branches (1)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/master
    No releases to show
  • c267948
  • /
  • glvu
  • /
  • matlabDeformer.h
Raw File Download Save again
Take a new snapshot of a software origin

If the archived software origin currently browsed is not synchronized with its upstream version (for instance when new commits have been issued), you can explicitly request Software Heritage to take a new snapshot of it.

Use the form below to proceed. Once a request has been submitted and accepted, it will be processed as soon as possible. You can then check its processing state by visiting this dedicated page.
swh spinner

Processing "take a new snapshot" request ...

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
  • revision
  • snapshot
origin badgecontent badge
swh:1:cnt:b0b48c02faa167fe87a5222fcd33fbafef31c7a1
origin badgedirectory badge
swh:1:dir:cf90c7a577b701392d16a2c3885de4cbc59b28a5
origin badgerevision badge
swh:1:rev:8da858a9a496faf7eb26f1854e8db3c57776c0e0
origin badgesnapshot badge
swh:1:snp:d460e09d7a0ebd508ffbb5fc8580c6584ff91442

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
  • revision
  • snapshot
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Tip revision: 8da858a9a496faf7eb26f1854e8db3c57776c0e0 authored by lwt831 on 30 April 2021, 08:00:14 UTC
Update Readme
Tip revision: 8da858a
matlabDeformer.h
#pragma once

#include "deformer.h"
#include "matlab_utils.h"
#include <thread>
#include <chrono>
#include <sstream>  
#include <iostream>  

extern bool showATB;
extern int viewport[4];



extern std::vector<std::string> method_names;
extern int method;
extern double w_smooth;

void display();
void meshDeform();
//void loadP2PConstraints();
using MatX3f = Eigen::Matrix<float, Eigen::Dynamic, 3, Eigen::RowMajor>;


inline std::string catStr(const std::vector<std::string> &names)
{
    std::string str;
    for (int i = 0; i < names.size(); i++) {
        str += names[i];
        if (i < names.size() - 1) str += ", ";
    }
    return str;
}

struct MatlabDeformer : public Deformer
{	
	int nIteration = 1;

    MyMesh &M;

    MatlabDeformer(MatlabDeformer&) = delete;

    MatlabDeformer(MyMesh &m) :M(m){

        using deformerptr = MatlabDeformer*;

        //////////////////////////////////////////////////////////////////////////
		method_names = matlab2strings("Deformer_Method");
        std::string default_method = matlab2string("Default_Deformer_Method");
        for (int i = 0; i < method_names.size(); i++) if (default_method == method_names[i]) method = i;
		createDeformer();
		for (int i = 0; i < method_names.size(); i++)
			matlabEval(method_names[i] + std::string(".set_p2p_weight(p2p_weight);"), false);
		
    }

    ~MatlabDeformer(){
        TwBar *bar = TwGetBarByName("Deformer");
        if (bar)    TwDeleteBar(bar); 
    }

   // virtual std::string name(){ return "P2PHarmonic"; }
	virtual void createDeformer()
	{
		matlabEval("createDeformer", false);
	}




    void deformResultFromMaltab(std::string resVarName1, std::string resVarName2)
    {
        using namespace Eigen;
		Matrix<float, Dynamic, Dynamic, RowMajor> y;
		Matrix<float, Dynamic, Dynamic, RowMajor> N;
        matlab2eigen(resVarName1,y,true);
		matlab2eigen(resVarName2, N, true);
		if (y.cols() > 3)  y = y.leftCols(3);
		if (y.rows() == 0 || y.cols() != 3) return;

		if (M.isSmooth)
		{
			MatX3f N;
			matlab2eigen("single(normY)", N, true);
			M.upload(y.data(), y.rows(), N.data(), nullptr, 0, nullptr);
		}
		else
		{			
			M.upload(y.data(), y.rows(), nullptr, 0, nullptr);
			
		}
		
    }

    virtual void deform()
    {
		using namespace Eigen;
		std::vector<int> P2PVtxIds = M.getConstrainVertexIds();
		std::vector<float> p2pDsts = M.getConstrainVertexCoords();
		eigen2matlab("view_P2PVtxIds", (Map<Array<int, Dynamic, 1>>(P2PVtxIds.data(), P2PVtxIds.size()) + 1).matrix().cast<double>());
		eigen2matlab("p2pDsts", Map<MatX3f>(p2pDsts.data(), P2PVtxIds.size(), 3).cast<double>());

		scalar2matlab("nIteration", nIteration);

		matlabEval(std::string("[viewY , Deformation_Converged] = ") + method_names[method] + std::string(".run(nIteration, view_P2PVtxIds, p2pDsts); "), false);
		if (M.isSmooth)
		{
			matlabEval("if(size(viewY,1) ~= size(viewX,1))\
				normY = vertexNormal(triangulation(t, viewY));\
			viewY(end + 1:end + numSeamVertex, : ) = viewY(seamVertexIndex, :);\
			normY(end + 1:end + numSeamVertex, : ) = normY(seamVertexIndex, :);\
			end", false);
		}
		else{
			matlabEval("if(size(viewY,1) ~= size(viewX,1))\
		viewY(end + 1:end + numSeamVertex, : ) = viewY(seamVertexIndex, :);\
		end", false);
		}
		//matlabEval("updateNormal", false);
        deformResultFromMaltab("single(viewY)", "single(normY)");
		if (M.vizVtxDistortion)
		{
			
			matlabEval(std::string("distortion = ") + method_names[method] + std::string(".computeVertexDistortion;"), false);
			matlabEval(std::string("distortion(end+1:end+numSeamVertex) = distortion(seamVertexIndex);"), false);

			auto distortion = matlab2vector<float>("single(distortion)", true);
			M.gpuVertexData.uploadData(distortion.data(), M.nVertex, false);
		}
    }

    virtual bool converged() {
        return !getMatEngine().hasVar("Deformation_Converged")  ||  matlab2scalar("Deformation_Converged") > 0;
    }

    virtual void resetDeform() {
		matlabEval(method_names[method] + std::string(".Reset;"), false);
		matlabEval("viewY = viewX;", false);
		matlabEval("normY = normX;", false);
		matlabEval("Deformation_Converged = 0", false);
		printf("====================================\n");
		printf("		reset mesh			\n");
		deformResultFromMaltab("single(viewY)", "single(normX)");
    }
    virtual void getResult() {}
    //virtual void saveData()   { matlabEval("p2p_harmonic_savedata;"); }
};

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API