Blender  V2.93
deg_builder_pchanmap.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2015 Blender Foundation.
17  * All rights reserved.
18  */
19 
25 
26 #include <cstdio>
27 #include <cstring>
28 
29 #include "BLI_utildefines.h"
30 
31 namespace blender::deg {
32 
33 /* Debug contents of map */
35 {
36  map_.foreach_item([](StringRefNull key, const Set<StringRefNull> &values) {
37  printf(" %s : { ", key.data());
38  for (StringRefNull val : values) {
39  printf("%s, ", val.data());
40  }
41  printf("}\n");
42  });
43 }
44 
45 /* Add a mapping. */
46 void RootPChanMap::add_bone(const char *bone, const char *root)
47 {
48  map_.lookup_or_add_default(bone).add(root);
49 }
50 
51 /* Check if there's a common root bone between two bones. */
52 bool RootPChanMap::has_common_root(const char *bone1, const char *bone2) const
53 {
54  const Set<StringRefNull> *bone1_roots = map_.lookup_ptr(bone1);
55  const Set<StringRefNull> *bone2_roots = map_.lookup_ptr(bone2);
56 
57  if (bone1_roots == nullptr) {
58  // fprintf("RootPChanMap: bone1 '%s' not found (%s => %s)\n", bone1, bone1, bone2);
59  // print_debug();
60  return false;
61  }
62 
63  if (bone2_roots == nullptr) {
64  // fprintf("RootPChanMap: bone2 '%s' not found (%s => %s)\n", bone2, bone1, bone2);
65  // print_debug();
66  return false;
67  }
68 
69  return Set<StringRefNull>::Intersects(*bone1_roots, *bone2_roots);
70 }
71 
72 } // namespace blender::deg
static bool Intersects(const Set &a, const Set &b)
Definition: BLI_set.hh:586
constexpr const char * data() const
Map< StringRefNull, Set< StringRefNull > > map_
bool has_common_root(const char *bone1, const char *bone2) const
void add_bone(const char *bone, const char *root)