~ubuntu-branches/ubuntu/karmic/gmsh/karmic

« back to all changes in this revision

Viewing changes to Geo/MVertex.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme, Christophe Prud'homme, Daniel Leidert
  • Date: 2008-05-18 12:46:05 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20080518124605-716xqbqeo07o497k
Tags: 2.2.0-2
[Christophe Prud'homme]
* Bug fix: "gmsh ships no .desktop", thanks to Vassilis Pandis (Closes:
  #375770). Applied the Ubuntu patch.

[Daniel Leidert]
* debian/control (Vcs-Svn): Fixed.
  (Build-Depends): Use texlive instead of tetex-bin.
* debian/gmsh.doc-base (Section): Fixed accordingly to doc-base (>= 0.8.10).
* debian/rules: Removed some variable declarations, that lead to double
  configuration and seem to be useless.
  (build/gmsh): Try to avoid multiple runs by using a stamp.
  (orig-tarball): Renamed to get-orig-source and changed to use uscan.
* debian/watch: Added.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// $Id: MVertex.cpp,v 1.13 2007-04-21 19:40:00 geuzaine Exp $
 
1
// $Id: MVertex.cpp,v 1.23 2008-03-29 21:36:29 geuzaine Exp $
2
2
//
3
 
// Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 
3
// Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle
4
4
//
5
5
// This program is free software; you can redistribute it and/or modify
6
6
// it under the terms of the GNU General Public License as published by
19
19
// 
20
20
// Please report all bugs and problems to <gmsh@geuz.org>.
21
21
 
22
 
#include <math.h>
 
22
#include <cstring>
 
23
#include <cmath>
23
24
#include "MVertex.h"
 
25
#include "GEdge.h"
 
26
#include "GFace.h"
 
27
 
 
28
#if defined(HAVE_GMSH_EMBEDDED)
 
29
#  include "GmshEmbedded.h"
 
30
#else
 
31
#  include "Message.h"
 
32
#endif
24
33
 
25
34
int MVertex::_globalNum = 0;
26
35
double MVertexLessThanLexicographic::tolerance = 1.e-6;
27
36
 
 
37
bool MVertexLessThanLexicographic::operator()(const MVertex *v1, const MVertex *v2) const
 
38
{
 
39
  if(v1->x() - v2->x() >  tolerance) return true;
 
40
  if(v1->x() - v2->x() < -tolerance) return false;
 
41
  if(v1->y() - v2->y() >  tolerance) return true;
 
42
  if(v1->y() - v2->y() < -tolerance) return false;
 
43
  if(v1->z() - v2->z() >  tolerance) return true;
 
44
  return false;
 
45
}
 
46
 
28
47
void MVertex::writeMSH(FILE *fp, bool binary, double scalingFactor)
29
48
{
30
 
  if(_num < 0) return; // negative vertices are never saved
 
49
  if(_index < 0) return; // negative index vertices are never saved
31
50
 
32
51
  if(!binary){
33
 
    fprintf(fp, "%d %.16g %.16g %.16g\n", _num, 
34
 
            x() * scalingFactor, 
35
 
            y() * scalingFactor,
36
 
            z() * scalingFactor);
 
52
    fprintf(fp, "%d %.16g %.16g %.16g\n", _index, 
 
53
            x() * scalingFactor, 
 
54
            y() * scalingFactor,
 
55
            z() * scalingFactor);
37
56
  }
38
57
  else{
39
 
    fwrite(&_num, sizeof(int), 1, fp);
 
58
    fwrite(&_index, sizeof(int), 1, fp);
40
59
    double data[3] = {x() * scalingFactor, y() * scalingFactor, z() * scalingFactor};
41
60
    fwrite(data, sizeof(double), 3, fp);
42
61
  }
43
62
}
44
63
 
45
64
void MVertex::writeMSH(FILE *fp, double version, bool binary, int num, 
46
 
                       int elementary, int physical)
 
65
                       int elementary, int physical)
47
66
{
48
67
  if(!binary){
49
68
    fprintf(fp, "%d 15", num);
51
70
      fprintf(fp, " %d %d 1", physical, elementary);
52
71
    else
53
72
      fprintf(fp, " 2 %d %d", physical, elementary);
54
 
    fprintf(fp, " %d\n", _num);
 
73
    fprintf(fp, " %d\n", _index);
55
74
  }
56
75
  else{
57
76
    int tags[4] = {num, physical, elementary, 0};
58
77
    fwrite(tags, sizeof(int), 4, fp);
59
 
    int verts[1] = {_num};
 
78
    int verts[1] = {_index};
60
79
    fwrite(verts, sizeof(int), 1, fp);
61
80
  }
62
81
}
63
82
 
64
83
void MVertex::writeVRML(FILE *fp, double scalingFactor)
65
84
{
66
 
  if(_num < 0) return; // negative vertices are never saved
 
85
  if(_index < 0) return; // negative index vertices are never saved
67
86
 
68
87
  fprintf(fp, "%.16g %.16g %.16g,\n",
69
 
          x() * scalingFactor, y() * scalingFactor, z() * scalingFactor);
 
88
          x() * scalingFactor, y() * scalingFactor, z() * scalingFactor);
70
89
}
71
90
 
72
91
void MVertex::writeUNV(FILE *fp, double scalingFactor)
73
92
{
74
 
  if(_num < 0) return; // negative vertices are never saved
 
93
  if(_index < 0) return; // negative index vertices are never saved
75
94
 
76
95
  int coord_sys = 1;
77
96
  int displacement_coord_sys = 1;
78
97
  int color = 11;
79
 
  fprintf(fp, "%10d%10d%10d%10d\n", _num, coord_sys, displacement_coord_sys, color);
 
98
  fprintf(fp, "%10d%10d%10d%10d\n", _index, coord_sys, displacement_coord_sys, color);
80
99
  // hack to print the numbers with "D+XX" exponents
81
100
  char tmp[128];
82
101
  sprintf(tmp, "%25.16E%25.16E%25.16E\n", x() * scalingFactor, 
83
 
          y() * scalingFactor, z() * scalingFactor);
 
102
          y() * scalingFactor, z() * scalingFactor);
84
103
  for(unsigned int i = 0; i < strlen(tmp); i++) if(tmp[i] == 'E') tmp[i] = 'D';
85
104
  fprintf(fp, tmp);
86
105
}
87
106
 
88
107
void MVertex::writeMESH(FILE *fp, double scalingFactor)
89
108
{
90
 
  if(_num < 0) return; // negative vertices are never saved
 
109
  if(_index < 0) return; // negative index vertices are never saved
91
110
 
92
111
  fprintf(fp, " %20.14G      %20.14G      %20.14G      %d\n", 
93
 
          x() * scalingFactor, y() * scalingFactor, z() * scalingFactor, 0);
 
112
          x() * scalingFactor, y() * scalingFactor, z() * scalingFactor, 0);
94
113
}
95
114
 
96
 
static void double_to_char8(double val, char *str){
 
115
static void double_to_char8(double val, char *str)
 
116
{
97
117
  if(val >= 1.e6)
98
118
    sprintf(str, "%.2E", val);
99
119
  else if(val >= 1.e-3)
106
126
    sprintf(str, "%f", val);
107
127
  else
108
128
    sprintf(str, "%.1E", val);
 
129
 
 
130
#if defined(WIN32)
 
131
  // Windows uses 3 digits in the exponent (which apparently does not
 
132
  // conform with ANSI C): remove the extra 0
 
133
  if(strlen(str) == 9 && (str[4] == 'E' || str[5] == 'E')){
 
134
    str[6] = str[7];
 
135
    str[7] = str[8];
 
136
  }
 
137
#endif
 
138
 
109
139
  str[8] = '\0';
110
140
}
111
141
 
112
142
void MVertex::writeBDF(FILE *fp, int format, double scalingFactor)
113
143
{
114
 
  if(_num < 0) return; // negative vertices are never saved
 
144
  if(_index < 0) return; // negative index vertices are never saved
115
145
 
116
146
  char xs[17], ys[17], zs[17];
117
147
  double x1 = x() * scalingFactor;
120
150
  if(format == 0){
121
151
    // free field format (max 8 char per field, comma separated, 10 per line)
122
152
    double_to_char8(x1, xs); double_to_char8(y1, ys); double_to_char8(z1, zs);
123
 
    fprintf(fp, "GRID,%d,%d,%s,%s,%s\n", _num, 0, xs, ys, zs);
 
153
    fprintf(fp, "GRID,%d,%d,%s,%s,%s\n", _index, 0, xs, ys, zs);
124
154
  }
125
155
  else if(format == 1){ 
126
156
    // small field format (8 char par field, 10 per line)
127
157
    double_to_char8(x1, xs); double_to_char8(y1, ys); double_to_char8(z1, zs);
128
 
    fprintf(fp, "GRID    %-8d%-8d%-8s%-8s%-8s\n", _num, 0, xs, ys, zs);
 
158
    fprintf(fp, "GRID    %-8d%-8d%-8s%-8s%-8s\n", _index, 0, xs, ys, zs);
129
159
  }
130
160
  else{ 
131
161
    // large field format (8 char first/last field, 16 char middle, 6 per line)
132
 
    fprintf(fp, "GRID*   %-16d%-16d%-16.9G%-16.9G*N%-6d\n", _num, 0, x1, y1, _num);
133
 
    fprintf(fp, "*N%-6d%-16.9G\n", _num, z1);
134
 
  }
 
162
    fprintf(fp, "GRID*   %-16d%-16d%-16.9G%-16.9G*N%-6d\n", _index, 0, x1, y1, _index);
 
163
    fprintf(fp, "*N%-6d%-16.9G\n", _index, z1);
 
164
  }
 
165
}
 
166
 
 
167
std::set<MVertex*, MVertexLessThanLexicographic>::iterator 
 
168
MVertex::linearSearch(std::set<MVertex*, MVertexLessThanLexicographic> &pos)
 
169
{
 
170
  double tol = MVertexLessThanLexicographic::tolerance;
 
171
  for(std::set<MVertex*, MVertexLessThanLexicographic>::iterator it = pos.begin();
 
172
      it != pos.end(); ++it){
 
173
    if(distance(*it) < tol) return it;
 
174
  }
 
175
  return pos.end();
 
176
}
 
177
 
 
178
void parametricCoordinates(const MVertex *ver, const GFace *gf, double &u, double &v)
 
179
{
 
180
  GEntity *ge = ver->onWhat();
 
181
  if(ge->dim() == 2){
 
182
    ver->getParameter(0, u);
 
183
    ver->getParameter(1, v);      
 
184
  }
 
185
  else if(ge->dim() == 1){
 
186
    double t;
 
187
    ver->getParameter(0, t);
 
188
    GEdge *ged = dynamic_cast<GEdge*>(ge);
 
189
    SPoint2 p = ged->reparamOnFace((GFace*)gf, t, 1);
 
190
    u = p.x();
 
191
    v = p.y();
 
192
  }
 
193
  else{
 
194
    GVertex *gver = dynamic_cast<GVertex*>(ge);
 
195
    SPoint2 p = gver->reparamOnFace((GFace*)gf, 1);
 
196
    u = p.x();
 
197
    v = p.y();
 
198
  }      
135
199
}