Welcome to mirror list, hosted at ThFree Co, Russian Federation.

admmpd_pin.h « src « softbody « extern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8080d9d2c85dc9364774d100b99088061f260a87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright Matt Overby 2020.
// Distributed under the MIT License.

#ifndef ADMMPD_PIN_H_
#define ADMMPD_PIN_H_

#include "admmpd_bvh.h"
#include "admmpd_types.h"
#include <unordered_map>
#include <vector>

namespace admmpd {

class Pin {
public:

    virtual ~Pin() {}

    // Clears all pins
    virtual void clear() = 0;

    // Set the pin location (q) and per-axis stiffness (k)
    // Stiffness should be 0 to 1. It can go larger, but
    // the resulting matrix will be poorly conditioned.
    virtual void set_pin(
        int idx,
        const Eigen::Vector3d &q,
        const Eigen::Vector3d &k) = 0;

    // Returns true if the vert is pinned
//    virtual bool has_pin(int idx) const = 0;

    // Creates linearization for constraint:
    // Px=q with stiffnesses baked in
    virtual void linearize(
        const Eigen::MatrixXd *x, // not used yet
    	std::vector<Eigen::Triplet<double> > *trips,
		std::vector<double> *q) = 0;

    // Returns per-axis pin stiffness
//    virtual Eigen::Vector3d get_pin_k(int idx) const = 0;

    // Returns pin location, or zero vector if not set
 //   virtual Eigen::Vector3d get_pin_pos(int idx) const = 0;
};

class EmbeddedMeshPin : public Pin {
public:
    EmbeddedMeshPin(const EmbeddedMeshData *mesh_) : mesh(mesh_){}

    // Clears all pins
    void clear();

    // Set the pin location of the embedded vertex
    void set_pin(
        int idx,
        const Eigen::Vector3d &p,
        const Eigen::Vector3d &k);

    // Returns true if the deforming vertex is pinned
//    bool has_pin(int idx) const;

    void linearize(
        const Eigen::MatrixXd *x, // not used yet
    	std::vector<Eigen::Triplet<double> > *trips,
		std::vector<double> *q);

    // Returns per-axis pin stiffness of the deforming vertex (not embedded)
    // or zero if not pinned
    // Baryweights are included.
//    Eigen::Vector3d get_pin_k(int idx) const;

    // Returns pin location of the deforming vertex (not embedded)
    // or zero vector if not set
//    Eigen::Vector3d get_pin_pos(int idx) const;

protected:
    // A ptr to the embedded mesh data
    const EmbeddedMeshData *mesh;

    // Pins for embedded vertices:
    std::unordered_map<int,Eigen::Vector3d> pin_k;
    std::unordered_map<int,Eigen::Vector3d> pin_pos;
};

} // namespace admmpd

#endif // ADMMPD_PIN_H_